Regular expressions

From: Date: Fri, 20 Apr 2001 12:14:50 +0000
Subject: Regular expressions
Groups: php.general 
Request: Send a blank email to php-general+get-49543@lists.php.net to get a copy of this message
Hi I have the script below which encases every occurance of span in a <span> tag The problem is I don't want it to replace any occurance of span that is inside a tag. how could I acheive this? I'm using perl regular expressions to keep the original case of the string. So, how could I replace occurances of span that aren't in a tag? Many thanks M@ ' my regular expressions book is in the post ################################################################# <style type="text/css"> <!-- .message {color: #FF0000;} --> </style> <?php $string = "<span class=message>span, span the span</span>"; echo $string.NL; $search = array("span"); echo "Count = ".count($search).NL; for($i=0;$i < count($search); $i++) { $result =$string; if(next($search) == false) { reset($search); } $bgstring = current($search); $result = preg_replace("/($bgstring+)/ie", "'<b>\\1</b>'", $result); } echo $result; ?> ################################################################

« previous php.general (#49543) next »