What’s the difference between strstr and substr

strstr:

It will return substring from the first matching occurrence to the end of string.

e.g.
$str = ‘abc.com';
echo strstr($str,’c’);
output :: c.com

substr:

It will return part of the string from the given index to its length parameters.

e.g.

$rest = substr(“”abcdef””, -1);    // returns “”f””
$rest = substr(“”abcdef””, -2);    // returns “”ef””
$rest = substr(“”abcdef””, -3, 1); // returns “”d”””

Posted in PHP | Tagged , , | Comments Off

Comments are closed.