I am using strpos() to find the needle in the haystack. But, I want it to only find the needle with the same string length. E.g.:
$mystring = '123/abc';
$findme = 'abc';
$pos = strpos($mystring, $findme); // THIS IS FINE
$mystring = '123/abcdefghijk';
$findme = 'abc';
$pos = strpos($mystring, $findme); // THIS IS NOT FINE
So, I need to check the string length of the found string and match that to the needle to see if they are the same length. So, 123/abc matches abc correctly, but I don’t want 123/abcdefghijk to match abc because it is much longer than 3 characters.
substr()can take a negative3 argument which counts from the end of the string. So figure out the length of the needle, count off that many characters from the end and compare it to the needle: