note 51321 added to function.preg-replace

From: Date: Sun, 27 Mar 2005 11:02:04 +0000
Subject: note 51321 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-87051@lists.php.net to get a copy of this message
preg_replace has some troubles with multi line strings. Here's a quick fix: $string = '<!-- SUB: JustASub--> <h1>test</h1> works like CharmeD! <!-- END SUB: JustASub -->'; $string = str_replace ( array ("\r\n", "\n", "\r"), array ('\r\n', '\n', '\r'), $string ); $string = preg_replace("/<!-- SUB: JustASub-->(.*)<!-- END SUB: JustASub -->/i", "\\1", $string); $string = str_replace ( array ('\r\n', '\n', '\r'), array ("\r\n", "\n", "\r"), $string ); echo $string; Returns: <h1>test</h1> works like CharmeD! ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51321 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51321&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51321&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51321&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51321&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51321&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51321&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#87051) next »