I am trying to use strpos to find out if a string exists and then use substr_replace to delete that string. My code is below:
$title=$item->get_title();
$stringToFind='Help needed identifying this person in ';
if(strpos($title,$stringToFind)){
$title=substr_replace($title,'',0,strlen($stringToFind));
}
However, when I do an echo on the strpos it always returns false when it should be true. So I’m wondering if strpos doesn’t do whitespace or something? IN which case can someone recommend something?
Why don’t you give this a shot :
The PHP documentation refers to the
str_replacefunction asIf the
$searchStrdoes not appear in the$titlevariable then the string will be left alone.However, if it exists – it will be removed. You don’t need to test if it exists at all. If you need to test whether a change has been made or not you could compare the length of the two strings using
strlenormb_strlendepending on your encoding.Example input/outputs :
CONSTANT –
$searchStr = 'Help needed identifying this person in ';