The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.34 / 5.00 31,296 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.07 / 5.00 10,082 ViewsI am using highlight.js to do my syntax highlighting for my site, and to work, it needs escaped code in between a pre and a code tag. What I am doing to make sure that the code is escaped is running a regular expression replace function that replaces text between the pre and code tags with escaped text between pre and code tags. My PHP looks like this:
preg_replace("/<pre><code>(.*?)<\/code><\/pre>/isUe","'<pre><code>'.htmlspecialchars('$1').'</code></pre>'",$post);
I have tested it, and it doesn't match any of my code blocks (usually the code blocks are HTML snippits that are unescaped). What is the problem with that regular expression? It should work fine, right?
Sorry for the double post, but newgrounds failed to unescape my < characters. They are not actually there; I only put them in to satisfy the html formatting rules for BBS posts.
This worked for me.
$post = "<pre><cod><p>some code</p></cod></pre>";
$post = preg_replace("/<pre>\s*<cod>(.*)<\/cod>\s*<\/pre>/isUe",
"'<pre><cod>'.htmlspecialchars('$1').'</cod></pre>'",
$post);
echo $post;
I left the e off of all code tags.
Hey thanks, I realized I left out the "$post = ", so it was replacing the code, and then not storing in a variable. A dumb mistake, for sure!