note 87712 deleted from function.preg-replace by danbrown

From: Date: Wed, 17 Dec 2008 22:15:01 +0000
Subject: note 87712 deleted from function.preg-replace by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-148284@lists.php.net to get a copy of this message
Note Submitter: montana [at] percepticon [.] c.o.m ---- coding across linux, mac, and windows - gets annoying dealing with line breaks in disparate config files etc. standardize to windoughs CRLF format since windoze has the most issues with other formats it seems. instead of using one terrible regex I just broke this up into smaller groups - may take longer to execute three statements rather than one, but it also granularizes the use case. $s = "Testing 1.\r" . "Testing 2.\n" . "Testing 3.\r\n" . "Testing 4.\n\r:END"; $s = preg_replace("/(?<!\\n)\\r+(?!\\n)/", " :REPLACED: \r\n", $s); //replace just CR with CRLF $s = preg_replace("/(?<!\\r)\\n+(?!\\r)/", " :REPLACED: \r\n", $s); //replace just LF with CRLF $s = preg_replace("/(?<!\\r)\\n\\r+(?!\\n)/", " :REPLACED: \r\n", $s); //replace misordered LFCR with CRLF echo $s; output: Testing 1. :REPLACED: Testing 2. :REPLACED: Testing 3. Testing 4. :REPLACED: :END

« previous php.notes (#148284) next »