Say I have a long UTF-8 encoded string.
And say I want to detect if $var
exists in this string.
Assuming $var
is always going to be simple letters or numbers of ascii characters (e.g. "hello123"
) I shouldn't need to use mb_strpos
or iconv_strpos
right? Because it doesn't matter if the position is not character-wise correct as long as its consistent with the other functions.
Example:
$var='hello123';
$pos=strpos($utf8string,$var);
if ($pos!==false) $uptohere=substr($ut8string,0,$pos);
Am I correct that the above code will extract everything up to 'hello123'
regardless of whether the string contains fancy UTF-8 characters? My logic is that because both strpos
and substr
will be consistent with each other (even if this is consistently wrong) then it should still work.
substr
will think exactly the same and so it will crop the string still at the correct point? – Dobbs