PHP Get First 3 Character from String Example

03-Apr-2023

.

Admin

PHP Get First 3 Character from String Example

Hi Dev,

This tutorial will give you example of php get first 3 Character from string example. I explained simply about how to get first Three Character from string in php?. We will use string to get first Three Character in php example. if you want to see example of get first Three Character from string in php example then you are a right place .

There are tow example to get First 3 Character from strings in PHP. in this example, we will use to substr() and mb_substr() function to get First 3 Character. so Let's both the following example with output.

Example 1: Get First 3 Character from String


index.php

<?php

$str = "Welcome to Nicesnippets.com";

//Get first Three character from a string

$result = substr($str,0,3);

echo $result;

?>

Output:

Wel

Example 2: Get First 3 Character from String

index.php

<?php

$str = "Hello World";

//Get first Three character from a string

$result = mb_substr($str,0,3);

echo $result;

?>

Output:

Hel

I hope it could help you...

#PHP