note 64791 deleted from function.strstr by bjori
| From: | bjori@php.net | Date: | Thu, 27 Apr 2006 09:17:44 +0000 |
| Subject: | note 64791 deleted from function.strstr by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-109834@lists.php.net to get a copy of this message | ||
Note Submitter: Johnny B Bad
----
In response to:
john :: beech :: at :: mkv25 :: dot :: net
Your function returns the portion of a string that occurs BEFORE the needle, a different approach to
the same means could be...
<?php
//returns portion of 'haystack' occuring before passed 'needle'
function grabStart($haystack,$needle) {
return strrev(ltrim(strstr(strrev($haystack),$needle),$needle));
}
//Example:
$haystack = 'Hello Buddy, I like you';
$needle = ',';
echo(grabStart($haystack,$needle));
//outputs 'Hello Buddy'
?>