papaface Posted April 10, 2009 Share Posted April 10, 2009 Hello, I am trying to search a string for a particular occurrence however I want it to work regardless of spaces. This is the code I have currently: $string = "Hello I am papa_face."; $pos = strpos($string, "I am papa_face"); if ($pos !== false) echo "Contains the string."; else echo "Does NOT contain the string."; Obviously in this example the string does contain the search term so it returns "Contains the string." However if I change the string to: $string = "Hello I am papa_face."; $pos = strpos($string, "I am papa_face"); if ($pos !== false) echo "Contains the string."; else echo "Does NOT contain the string."; The string is not found. How can I get around this? Link to comment https://forums.phpfreaks.com/topic/153481-solved-replace-multiple-spaces-with-one-space/ Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 As you stated in the subject of this topic, you can replace white space. You could try completely removing white space in both strings with something like this: $string = str_replace(' ', '', $string); //or with regex maybe? $string = preg_replace('/\s/', '', $string); Link to comment https://forums.phpfreaks.com/topic/153481-solved-replace-multiple-spaces-with-one-space/#findComment-806388 Share on other sites More sharing options...
papaface Posted April 10, 2009 Author Share Posted April 10, 2009 Thanks That worked Link to comment https://forums.phpfreaks.com/topic/153481-solved-replace-multiple-spaces-with-one-space/#findComment-806414 Share on other sites More sharing options...
jackpf Posted April 10, 2009 Share Posted April 10, 2009 Cool Link to comment https://forums.phpfreaks.com/topic/153481-solved-replace-multiple-spaces-with-one-space/#findComment-806422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.