i’m trying to decode strings between tow special tags with htmlspecialchars_decode and preg_replace, for example my original string is like this:
other strings...[link]<a href="http://example.com" target="_blank">example</a>[/link]other strings...
i need to convert everything between [link][/link] to html original code. tested this:
$str = preg_replace("/[link](.*)[\/link]/eisU", "htmlspecialchars_decode('$1')", $str);
dosen’t worked! i searched google and SO too but was useless!
You have to escape the square brackets, otherwise
[link]is interpreted a character set comprising the lettersl, i, n, k.You should use
preg_quote()if you’re not sure about what to escape:This will do too: