note 20281 added to function.preg-replace

From: Date: Thu, 28 Mar 2002 16:17:35 +0000
Subject: note 20281 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-28340@lists.php.net to get a copy of this message
After pulling all my hear out, I figure out that regexps can't handle newlines. For my PHP parser code, I had the use this: <?php $cont = ' Some text that doesn\'t have to be parsed <?php echo \'This should be working\'; ?'.'>'; function parse_php($cont) { $cont = str_replace('{{=NEW-LINE=}}', "\n", $cont); ob_start(); eval($cont); $val = ob_get_contents(); ob_end_clean(); return $val; } $ret = str_replace("\n", '{{=NEW-LINE=}}', $ret); $ret = preg_replace('/<\?php(.+?)\?'.'>/e', 'parse_php(\'\\1\')', $ret); $ret = str_replace('{{=NEW-LINE=}}', "\n", $ret);echo $ret; ?> Would Give: Some text that doesn't have to be parsed This should be working -- http://www.php.net/manual/en/function.preg-replace.php http://master.php.net/manage/user-notes.php?action=edit+20281 http://master.php.net/manage/user-notes.php?action=delete+20281 http://master.php.net/manage/user-notes.php?action=reject+20281

« previous php.notes (#28340) next »