Re: urgent !!! Please Help preg_replace !!!!!!!!!!!!!!!!!!!!!

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

 



On Mon, 2008-02-11 at 13:42 +0900, Michael Moyle wrote:
> Rob,
> 
> 
> > $reps = array
> > (
> >     array
> >     (
> >         'match'   => '#<a.*</a>#Uims',
> 
> Can you explain what the 'U' from #Uims does? Does it have to do with
> Unicode? I can't find it anywhere (preg_match doc, man perlre, man
> perlop).


It makes the match "Ungreedy". Look at the following example:

    $text = "<a href="">blah</a> ... <a href="">bleh</a>";

If we match with the following:

    preg_match_all( '#<a.*</a>#Uims', $html, $matches )

Then $matches will contain 2 matches...

    1. <a href="">blah</a>
    2. <a href="">bleh</a>

However if we match with the following:

    preg_match_all( '#<a.*</a>#ims', $html, $matches )

Then $matches will only get 1 match...

    1. <a href="">blah</a> ... <a href="">bleh</a>

This is because the default behaviour is greedy, it will match as much
as possible even if a shorter match exists.

Cheers,
Rob.
-- 
.------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for       |
| creating re-usable components quickly and easily.          |
`------------------------------------------------------------'

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux