Reply to Re: single array to multidimensional

Your name:

Reply:


Posted by frizzle on 06/23/06 14:47

Chung Leong wrote:
> frizzle wrote:
> > Chung Leong wrote:
> > > 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.
> >
> > Ok, thanks, this named capturing is new to me, but looks kind of ideal!
> > Thanks a lot guys!
> >
> > I have one little question left, not really essential, but to clean
> > things up:
> > can the preg-match-all be adjusted that output would be
> >
> > [0] => Array
> > (
> > [name] => Google
> > [url] => http://www.google.com
> > )
> >
> > instead of (current):
> >
> > [0] => Array
> > (
> > [0] => Google,http://www.google.com
> > [name] => Google
> > [1] => Google
> > [url] => http://www.google.com
> > [2] => http://www.google.com
> > )
> >
> > per name/url -set ?
> >
> > Frizzle.
>
> No, unfortunately. I wish an option like that exists.

No problem, i reached my goal with all of your help, and things are
fixed properly.
Thanks again!

Frizzle.

[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

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