note 79087 added to function.strstr
| From: | root at mantoru dot de | Date: | Sat, 10 Nov 2007 11:22:43 +0000 |
| Subject: | note 79087 added to function.strstr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132160@lists.php.net to get a copy of this message | ||
Please note that $needle is included in the return string, as shown in the example above. This ist
not always desired behavior, _especially_ in the mentioned example. Use this if you want everything
AFTER $needle.
<?php
function strstr_after($haystack, $needle, $case_insensitive = false) {
$strpos = ($case_insensitive) ? 'stripos' : 'strpos';
$pos = $strpos($haystack, $needle);
if (is_int($pos)) {
return substr($haystack, $pos + strlen($needle));
}
// Most likely false or null
return $pos;
}
// Example
$email = 'name@example.com';
$domain = strstr_after($email, '@');
echo $domain; // prints example.com
?>
----
Server IP: 217.13.201.10
Probable Submitter: 78.51.71.22
----
Manual Page -- http://www.php.net/manual/en/function.strstr.php
Edit -- https://master.php.net/note/edit/79087
Del: integrated -- https://master.php.net/note/delete/79087/integrated
Del: useless -- https://master.php.net/note/delete/79087/useless
Del: bad code -- https://master.php.net/note/delete/79087/bad+code
Del: spam -- https://master.php.net/note/delete/79087/spam
Del: non-english -- https://master.php.net/note/delete/79087/non-english
Del: in docs -- https://master.php.net/note/delete/79087/in+docs
Del: other reasons-- https://master.php.net/note/delete/79087
Reject -- https://master.php.net/note/reject/79087
Search -- https://master.php.net/manage/user-notes.php