Jump to content

Regex Question


MinusMyThoughts

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...