note 87816 added to function.preg-replace

From: Date: Tue, 23 Dec 2008 20:47:20 +0000
Subject: note 87816 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-148483@lists.php.net to get a copy of this message
/* Coding across linux, mac, and windows gets annoying dealing with errors resulting from EOL format in config files, etc. Standardize to CRLF format. Instead of using one 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. */ //different formats all living together $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: 209.41.74.194 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/87816 Del: integrated -- https://master.php.net/note/delete/87816/integrated Del: useless -- https://master.php.net/note/delete/87816/useless Del: bad code -- https://master.php.net/note/delete/87816/bad+code Del: spam -- https://master.php.net/note/delete/87816/spam Del: non-english -- https://master.php.net/note/delete/87816/non-english Del: in docs -- https://master.php.net/note/delete/87816/in+docs Del: other reasons-- https://master.php.net/note/delete/87816 Reject -- https://master.php.net/note/reject/87816 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148483) next »