| px | top | add code | search | signup | login | help |
<?php
/****
This function finds the first occurance of the substring $search within the
string $text. If $mode is equal to zero, it will return the starting
position of the substring. Otherwise, it will return the position of
the character that comes after the substing.
Returns -1 if the substring is not found.
****/
function findstring($text, $search, $mode){
$returnval = -1;
$foundit = 0;
$tlen = strlen($text);
$slen = strlen($search);
for($n = 0; $text[$n] != $NULL && $foundit == 0; $n++){
for($m = 0; ($text[$n + $m] == $search[$m]) && ($n + $m < $tlen) && ($m < $slen); $m++);
if($m >= $slen)
$foundit = 1;
}
if($foundit){
if(!$mode) $returnval = $n - 1;
else $returnval = $m + $n - 1;
}
return $returnval;
}
?>
Comments or questions?
PX is running PHP 5.2.11
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.