Blog Details

how to get first four characters from string in PHP


                                
                                    <?php

echo $x="wama software";
echo "<br>";
echo substr($x, 0, 4); //returns "wama"
echo "<br>";
echo "<br>";
echo "Some other examples too..";
echo substr ($x, 0, 3);  // outputs wam
echo "<br>";
echo substr ($x, 1, 1);  // outputs a
echo "<br>";
echo substr ($x, -2);    // outputs re
echo "<br>";
echo substr ($x, 1);     // outputs ama software
echo "<br>";
echo substr ($x, -2, 1); // outputs r
echo "<br>";


?>

output : 

wama software

Some other examples too..
wama
wam
a
re
ama software
r
                                    


Categories

Core_PHP

Latest posts

13.05.14
Implementing CRUD Operations ΒΆ

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote