note 87712 added to function.preg-replace

From: Date: Wed, 17 Dec 2008 22:11:44 +0000
Subject: note 87712 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-148283@lists.php.net to get a copy of this message
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 ---- Server IP: 64.71.164.2 Probable Submitter: 76.14.100.80 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/87712 Del: integrated -- https://master.php.net/note/delete/87712/integrated Del: useless -- https://master.php.net/note/delete/87712/useless Del: bad code -- https://master.php.net/note/delete/87712/bad+code Del: spam -- https://master.php.net/note/delete/87712/spam Del: non-english -- https://master.php.net/note/delete/87712/non-english Del: in docs -- https://master.php.net/note/delete/87712/in+docs Del: other reasons-- https://master.php.net/note/delete/87712 Reject -- https://master.php.net/note/reject/87712 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148283) next »