[pmwiki-users] Dumb question... stripping returns?

Christian Schlatter ch at schlatter.net
Mon Aug 8 04:42:27 CDT 2005


Russell Bailey wrote:
> I'd like to strip out extraneous carriage returns in user edits.  I'm
> having a devil of a time getting the replace string right,  though.  I'm
> pretty sure I'm making a simple error... anyone recognize it?
> 
> $new['text'] = str_replace("/[\n|\r]{2,}/", '\n', $new['text']);

You should use a single quoted string for the pattern, since otherwise 
the sequences \n and \r get translated into CR and LF. So I'd try

$new['text'] = str_replace('/[\n|\r]{2,}/', '\n', $new['text']);

Hope that helps,
ChristianS




More information about the pmwiki-users mailing list