Re: eregi sentence

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ivan hello
Yoy really help me a lot!
Thanx

----- Original Message ----- 
From: "Ivan Fomichev" <johnny@xxxxxxxxxx>
To: "Nikos Gatsis" <php-db@xxxxxxxxxxxxx>
Sent: Sunday, November 30, 2003 6:56 PM
Subject: Re:  eregi sentence


> Hello Nikos,
>
> Sunday, November 30, 2003, 10:29:19 AM, you wrote:
>
> NG> Can somebody tell me what is wrong with the following?
> NG> $body=eregi_replace("<a href=\"(.+)\"([^>]*)>(.+)</a>", "<a
href=\"\\1\"
> NG> target=\"_blank\" class=\"down_txt\"><strong>\\3</strong></a>",
$body);
>
> 1) /.+/ is too greedy. You should use something like /[^"]+/ or /.+?/
instead
>    (second is supported only in Perl-compatible regexps). The best
solution
>    could be /[^'"]+?/ however.
> 2) /<a / doesn't match "\n" after "a".
>
>    $body = preg_replace(
>        '#<[Aa]\s[^>]*?[Hh][Rr][Ee][Ff]\s*=\s*([\'"])([^\'">]+?)\1[^>]*?>'
.
>            '([^<]*?)</a[^>]*?>#s',
>        '<A href="\2" target="_blank" class="down_txt">' .
>            '<strong>\3</strong></a>',
>        $body
>    );
>
>    This regexp is not perfect, but I hope it has enough margin of safety,
at
>    least if your HTML code is more or less correct. E. g., all href values
>    must be quoted and '<', '>', '"' and "'" without special meaning must
be
>    written as HTML entities.
>
> -- 
> Best regards,
>  Ivan                            mailto:johnny@xxxxxxxxxx
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux