This adds a new line for every whitespace character: $after=preg_replace('/\s+/','\n\n',$before); I need it to replace any new line that contains extra whitespace characters with just a new line. I THOUGHT it should look something like this: $after=preg_replace('/\n/\s+//\n','\n\n',$before); But it doesn't work! Any ideas? Thanks!
Here the the correct format for preg_replace $patterns = array ('/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/', '/^\s*{(\w+)}\s*=/'); $replace = array ('\3/\4/\1\2', '$\1 ='); echo preg_replace($patterns, $replace, '{startDate} = 1999-5-27'); Code (markup): $str = 'foo o'; $str = preg_replace('/\s\s+/', ' ', $str); Code (markup): http://us3.php.net/preg_replace
Try this: $after = preg_replace('/\A\s+\Z/','',$before); Or this: $after = preg_replace('/\n\s+\n/',"\n\n",$before);
Umm... yet another lapse on concentration. The first one should be: $after = preg_replace('/^\s+$/m', '', $before); Code (markup): The second one should still be fine if you prefer it.