note 44900 deleted from function.strpos by felipe
| From: | felipe@php.net | Date: | Thu, 03 Jan 2008 02:14:24 +0000 |
| Subject: | note 44900 deleted from function.strpos by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134705@lists.php.net to get a copy of this message | ||
Note Submitter: christian dot NEI_TIL_SPAM at datalogen dot no
----
If you want to find the position of the first character succeeding $needle, this function does it
for you. $offset is optional.
<?php
function strpos_succ($haystack, $needle) {
$offset = (func_num_args() > 2) ? func_get_arg(2) : 0;
$res = strpos($haystack, $needle, $offset);
return (($res === false) ? false : $res + strlen($needle));
}
?>
Example:
<?php
$str = 'Mighty <a href="nowhere.htm">useful</a> function, this
strpos_succ!';
//Where does the first <a> tag in $str end?
$aPos = strpos_succ($str, ">");
// $aPos=29
?>