strpos, strrpos, substr


$string = "search the position of the first, search the position of the last inside the string";
$search = "position";
$pos = strpos($string, $search);
echo $pos;
echo "<br>";
echo "<br>";

$pos2 = strrpos($string, $search);
echo $pos2;
echo "<br>";
echo "<br>";

$return = substr($string, $pos);
echo $return;

echo "<br>";
echo "<br>";
$return2 = substr($string, $pos2);
echo $return2;

echo "<br>";
echo "<br>";
//Find the position of the last occurrence of "php" inside the string:
echo strrpos("I love php, I love php too!","php");

echo "<br>";
echo "<br>";

//Find the position of the first occurrence of "php" inside the string:
echo strpos("I love php, I love php too!","php");

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s