I'm using this UDF for the PREG_REPLACE function in MySQL and everything seems to be working fine so far. However, my goal now is to find and encode entities inside pre
tags in a column. So ultimately I'd like to get this:
<pre>
<strong>Hello World!</strong>
</pre>
To look like this:
<pre>
<strong>Hello World!</strong>
</pre>
I'm using the PREG_REPLACE function to find the contents inside the pre
tags like this:
SELECT PREG_REPLACE('/<pre>(.*?)<\\/pre>/sm', '\\1', '<pre><strong>Hello World</strong></pre>');
Now I'd like to replace \\1
with something that would say "replace with ENCODE_ENTITIES('\\1')
. Obviously it could be any other function, like UPPER
for example, but UPPER('\\1')
doesn't give much. I kind of like the idea of PREG_REPLACE_EVAL
in PHP's implementation of preg_replace
which allows something like this:
preg_replace("/(<\/?)(\w+)([^>]*>)/e",
"'\\1'.strtoupper('\\2').'\\3'",
$html_body);
Any ideas on how to implement something similar in MySQL? Or maybe I'm heading the wrong way? Thanks!