frost Posted August 21, 2007 Share Posted August 21, 2007 $Text = preg_replace("/\[code\](.+?)\[\/code\]/is","$CodeLayout", $Text); I am pretty sure the above code is from phpbb and is used as the code tag, similar to the forums here on php freaks. In this example everything between the opening and closing "code" tags are replaced by the $codelayout variable. I am wondering if there is a similar thing that will replace all of the < and > tags with < and > Any help would be much appreciated, my reg expression knowledge is nil Quote Link to comment Share on other sites More sharing options...
trq Posted August 21, 2007 Share Posted August 21, 2007 You could simply use htmlspecialchars. Quote Link to comment Share on other sites More sharing options...
frost Posted August 21, 2007 Author Share Posted August 21, 2007 I need to target in between the code tags specifically. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 21, 2007 Share Posted August 21, 2007 Use the /e modifier: $Text = preg_replace("/\[code\](.+?)\[\/code\]/ise",'htmlspecialchars("$1")', $Text); Quote Link to comment Share on other sites More sharing options...
frost Posted August 21, 2007 Author Share Posted August 21, 2007 You sir, are a scholar and a gentleman. So now I have this: $Text = '+code+<a href="test.php">test</a>+/code+'; $Text = preg_replace("/\[code\](.+?)\[\/code\]/ise",'htmlspecialchars("$1")', $Text); echo $Text; Which outputs: <a href="test.php">test</a> Which is exactly what I needed. Cheers! Edit: replaced [ and ] with + in my example so the forum would let it show. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.