Php > Algorithms
This function returns the position of string s1 within string s2
This function returns the position of string s1 within string s2 The position is 1 based. If s1 is not in s2, 0 is returned $begin + 1) { $middle = ceil(($begin + $end) / 2); $leftBegin = $begin; $rightBegin = $middle + $s1len; $leftEnd = $middle; $rightEnd = $end + $s1len; //Check left first if(ereg($s1, substr($s2, $leftBegin, $rightBegin - $leftBegin))) { $end = $middle; } else //(ereg($s1, substr($s2, $leftEnd, $rightEnd - $leftEnd))) { $position += $middle - $begin; $begin = $middle; } } //Resolve 1 off problems introduced by ceil if(ereg($s1, substr($s2, $end, $s1len))) $position++; //Return position 1 based return $position + 1; } ?>
Php Codes
Algorithms
Arrays
Authentication
Calendar
Code Snippets
Programs
Content Manage
Contest Related
Cookies
Credit Cards
DBase Related
Databases
Date Time
Directories
E-Mail
Errors
File
File System
Forms
Handling
Graphics
HTML and PHP
Informix
Ingres
InterBase
LDAP
Look and Feel
Miscellaneous
MySQL
Other
PHP Classes
Searching
Navigation
Statistics
Strings
User Manage