|
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]
|