tyuret
asked on
php search for first occurrence of multiple characters
Can anybody help?
Thank you
I want a function gives me the position of the first occurrence any of the elements in $haytack.
eg: Will return position of the comma(,) in $haystack since comma is the first element of the array that occurs in $haystack
$needles= Array ("'",">","<",")",",");
$haystack="test test , ) ' >>><<";
Thank you
I want a function gives me the position of the first occurrence any of the elements in $haytack.
eg: Will return position of the comma(,) in $haystack since comma is the first element of the array that occurs in $haystack
$needles= Array ("'",">","<",")",",");
$haystack="test test , ) ' >>><<";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The algorithm I provided will not be efficient if you have very long values of $haystack with the needles first occurring deep within it. In that case, you'd be best to go through the haystack a character at a time looking at whether any of the needles match and stopping at the first match.