MinusMyThoughts Posted August 3, 2008 Share Posted August 3, 2008 Hey, all!I'm trying to create a feature where a user can display code on their site by enclosing it in a span (<span class="code">).Here's what I'm trying to do right now:Use preg_replace() to pull out the content between span tags, then run the str_replace function in the replacement pattern to swap angle brackets for their HTML entity equivalents.Here's what I'm trying to use: $pattern = '/^<span class="code">(.*)<\/span>$/'; $regex = preg_replace($pattern,"'<span class=\"code\">' . str_replace('<','$lt;',$1) . '</span>'",stripslashes($_POST['data'])); I know that the match is working, because when I swapped my replacement for plain text, it works fine. However, when I try to use this replacement pattern, nothing happens.Any help or resources you could offer would be great! I've been poring over articles, and I just can't seem to get this working...Thanks!-Jason Link to comment Share on other sites More sharing options...
jeffman Posted August 3, 2008 Share Posted August 3, 2008 Assuming you don't want to write a more thorough regex, make these changes:$pattern = '/^<span class="code">(.*)<\/span>$/e';str_replace('<', '<', '$1') Link to comment Share on other sites More sharing options...
MinusMyThoughts Posted August 3, 2008 Author Share Posted August 3, 2008 Thanks! If I were to want to write a more thorough regex, what would you suggest?I keep trying to get regex, but I don't use it often enough, so it always seems like I'm learning it for the first time...Thanks again!-Jason Link to comment Share on other sites More sharing options...
Jesdisciple Posted August 4, 2008 Share Posted August 4, 2008 You might take a look at http://www.php.net/manual/en/function.htmlentities.php; other than that, I'm not sure what's incomplete. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.