socalnate Posted July 29, 2007 Share Posted July 29, 2007 $link = preg_replace(" ", "_", $link); I get an error Warning: preg_replace() [function.preg-replace]: Empty regular expression in So how do you represent whitespace in preg_replace? Nathan Link to comment https://forums.phpfreaks.com/topic/62381-solved-preg_replace-whitespace-for-underscore/ Share on other sites More sharing options...
Humpty Posted July 30, 2007 Share Posted July 30, 2007 I've not tested but a google search gave me these: ALL WHITESPACE NOT JUST THE SPACE CHARACTER: $after=preg_replace('/\s+/','',$before); ALL SPACES: $nospaces = str_replace(' ', '', $input); NEWLINE AND CARRIAGE RETURN: (added just in case you needed it too) str_replace("\n", '', $input); str_replace("\r", '', $input); EDIT: Decided to come back and identify the code as code (sorry) Link to comment https://forums.phpfreaks.com/topic/62381-solved-preg_replace-whitespace-for-underscore/#findComment-310472 Share on other sites More sharing options...
socalnate Posted July 30, 2007 Author Share Posted July 30, 2007 Found an ereg_replace that worked perfect $link = ereg_replace("[ \r\t\n]+", "_", $link); $link = strtolower($game_name_link1); echo "<a href=\"http://www.mysite.com/portal/{$link}.html\" Link to comment https://forums.phpfreaks.com/topic/62381-solved-preg_replace-whitespace-for-underscore/#findComment-310514 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.