|
Posted by gosha bine on 05/25/07 08:16
On 25.05.2007 01:24 Terence wrote:
> I've been puzzling over something for ages and now give up:
>
> Does anyone see any problem with any of the following:
>
> $line = preg_replace('/\[#([A-Fa-z0-9]{1,6})\]/i', "<font color='#
> ${1}'>", $line);
>
> $line = preg_replace('/\[(#(([A-Fa-f0-9]){3}(([A-Fa-f0-9]){3})?))\]/
> i', "<font color='#${1}'>", $line);
>
> I tried both ; both don't work.
>
> This snippet should convert something like [#FF0000] (hex colours)
> into an HTML font tag. I believe the reg.exp IS matching (since I do
> get a <font> tag), but the backreferencing is not working since the
> font tag would contain an empty hex code.
>
> I've tried using \\1 for the backreferencing, or even \\0 just to test
> - but even that doesn't work.
>
> Is it possible that backreferencing can just be turned off?!?
>
> - Terence
>
$line = preg_replace('/\[(#[A-F0-9]+)\]/i', "<font color='$1'>", $line);
the correct syntax is $1 not ${1} or similar.
--
gosha bine
extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok
Navigation:
[Reply to this message]
|