note 20281 deleted from function.preg-replace by sniper

From: Date: Sun, 07 Sep 2003 22:08:43 +0000
Subject: note 20281 deleted from function.preg-replace by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55715@lists.php.net to get a copy of this message
Note Submitter: gyrbo[@]yahoo[.]com ---- 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

« previous php.notes (#55715) next »