Reply to Re: single array to multidimensional

Your name:

Reply:


Posted by Chung Leong on 06/23/06 14:04

frizzle wrote:
> frizzle wrote:
> > Andy Hassall wrote:
> > > On 22 Jun 2006 13:21:50 -0700, "Chung Leong" <chernyshevsky@hotmail.com> wrote:
> > >
> > > >Andy Hassall wrote:
> > > >>
> > > >> There are undoubtably faster, more concise and cleverer ways of doing this.
> > > >
> > > >Which would involve, of course, regular expression :-)
> > > >
> > > >preg_match_all('/(?P<name>[^,]+),(?P<url>[^,]+)/', $list, $m,
> > > >PREG_SET_ORDER);
> > >
> > > Ah ha, was trying to work out how to get it with PCRE, knew it was possible
> > > :-)
> > >
> > > --
> > > Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
> > > http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
> >
> > I'm sorry, but i don't completely understand the logics in the
> > Disny-function, and i don't completely understand the logics in the
> > pattern of the preg_match_all part.
> >
> > Could someone please explain a little bit more ?
> >
> > Frizzle.
>
> Especially the "?P" - part in the pattern i cannot figure out ...
>
> Frizzle.

The use of (?P<> ... ) indicates named capturing. It only affects how
the captured texts are referenced. Neither the P, the angle brackets,
or the text inside them are a part of the pattern. Thus

/(?P<name>[^,]+),(?P<url>[^,]+)/

is the exact same pattern as

/([^,]+),([^,]+)/

Compare the results from using the two and you'll see the difference.
Here a code snippet:

<?php

header('Content-Type: text/plain');
$list = "Google,http://www.google.com";
preg_match_all('/([^,]+),([^,]+)/', $list, $m1, PREG_SET_ORDER);
preg_match_all('/(?P<name>[^,]+),(?P<url>[^,]+)/', $list, $m2,
PREG_SET_ORDER);
var_dump($m1);
var_dump($m2);

?>

Look in the manual for how preg_match_all() works.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация