Hi everybody.
I'm working on a project that involves pseudo HTML tags, like in this forum.
There's one tag named [jump]text[/jump] which creates a link to a predefined position.
Resulting HTML is
<A HREF="/link/somewhere.html">text</A>.
The code I use to do this is:
$str = preg_replace("/[jump](.*?)[\/jump]/ie", "'<A HREF=\"' . \$this->jump('','') . '\">\1</A>'", $str);
As you see I'm putting the thing through a method "jump". Rest asured that both this regexp and the jump method do what they are expected to.
Another tag I use is [img [parameters]]imageurl[/img]
It is an extended version of the tag used in many BBS. "My" version enables to perform somthing like this:
[img border="0" alt="click me" width="100"]imageurl[/img]
which becomes
<IMG src="imageurl" border="0" alt="click me" width="100">
The regexp used is:
$str = preg_replace("/[img(.?)?](.?)[\/img]/i", '<IMG src="\2"\1>', $str);
Again, this works.
My problem appears when I combine both:
[jump][img border="0" alt="click me" width="100"]imageurl[/img][/jump]
which should become:
<A HREF="link/somewhere.html"><IMG src="imageurl" border="0" alt="click me" width="100"></A>
but instead becomes:
<A HREF="link/somewhere.html"><IMG src="imageurl" border=\"0\" alt=\"click me\ width=\"100\"></A>
Please note the escaped "s as well as the one missing " after the alt part.
The jump command gets parsed before the img command. Reversing the order leads to further escaped "s at the src part of the img tag.
What the heck happens here and more important: How can I prevent it?
Thanks in advance,
Dominique