Reply to Re: regex help

Your name:

Reply:


Posted by Daniel Tryba on 10/04/97 11:20

Sugapablo <russ@removesugapablo.com> wrote:
> We can assume that the tags will always be written properly.

So why did you make an error in your example? :)

[string]
> ...I'd need the code to return, probably an array, like this:
> $array[0] = Allegheny River
> $array[1] = PNC Park
> $array[2] = 37,259
>
>
> I just can't get it. Any suggestions?

Tell us where you are running into problems. It's really simple if:
-you know the correct function
-you know your regexpes.

Do you want to learn how to do it or do you just want the answer of how
to get an array like:

Array
(
[0] => Array
(
[0] => <tag class="name">Allegheny River</tag>
[1] => <tag class="name">PNC Park</tag>
[2] => <tag class="name">37,259</tag>
)

[1] => Array
(
[0] => Allegheny River
[1] => PNC Park
[2] => 37,259
)
)

If you want to learn see
http://nl2.php.net/manual/en/function.preg-match-all.php (the examples
contain samples that match your question closely) and
http://nl2.php.net/manual/en/reference.pcre.pattern.syntax.php (study
greedy vs. non greedy)

The spoiler is below:






















preg_match_all('/<tag class="name">(.*?)<\/tag>/',$str,$matches);

[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

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