dreamwest Posted February 9, 2009 Share Posted February 9, 2009 Occasionally i have stings with "?" and " ' " and "," in them How can i get rid of these in one hit Example normal string: $title = "dog walks down path" str_replace(' ', '_', trim($title)) Outputs: dog_walks_down_path Example of string with ? and ' and , in it: $title = "i'd like to see the dog, wouldn't you?" str_replace(' ', '_', trim($title)) Outputs: i'd_like_to_see_the_dog,_wouldn't_you? You can see the problem, i need the output to be: id_like_to_see_the_dog_wouldnt_you Instead of: i'd_like_to_see_the_dog,_wouldn't_you? Quote Link to comment https://forums.phpfreaks.com/topic/144431-multiple-str_replace/ Share on other sites More sharing options...
Philip Posted February 9, 2009 Share Posted February 9, 2009 You can do an array of characters to clean $array = array('\'', ',', '?'); str_replace($array, '_', $title); Quote Link to comment https://forums.phpfreaks.com/topic/144431-multiple-str_replace/#findComment-757897 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.