Reputation: 46
How could I replace some markup in this format:
[a href="/my_page" style="font-size: 13px"]click me[/a]
to
<a href="/my_page" style="font-size: 13px">click me</a>
using preg_replace()?
I will need to allow for more attributes as well.
Upvotes: 2
Views: 2604
Reputation: 160883
$s = '[a href="/my_page" style="font-size: 13px"]click me[/a]';
$ret = preg_replace('~\[([^\[\]]+)\]([^\[\]]++)\[/([^\[\]]++)\]~', '<\1>\2</\3>', $s);
Upvotes: 2