You are here: Re: preg_match_all « PHP Programming Language « IT news, forums, messages
Re: preg_match_all

Posted by Csaba Gabor on 03/30/06 00:42

Mark Knochen wrote:
> Über <a href="[linkto:13]">allen</a> strahlt die <a
> href="[linkto:14]">Sonne</a> - <a href="[linkto:13]">über</a> allen in
> der Welt.
>
> preg_match_all('/\[linkto:(.*)\]/',$text,$linkto);
> $num = count($linkto['1']);
> echo $num;
>
> Why i get only 1 and not 3 results?

You should have examined the match that was found, and then you would
have seen: that '.*' is greedy. This means that the first 'linkto:' is
found and the the regular expression machine tries to use as many
characters as it can before it encounters the next one, which is the
**last** ']', hence only one match.

To get your three matches, you could replace '.*' with '.*?' which
makes the * non greedy.

Csaba Gabor from Vienna

 

Navigation:

[Reply to this 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

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