You are here: Re: [PHP] Problem with Regexp « PHP « IT news, forums, messages
Re: [PHP] Problem with Regexp

Posted by Yannick Mortier on 11/01/05 00:40

Richard Heyes schrieb:

> Yannick Mortier wrote:
>
>> Hello,
>>
>> I have the string:
>>
>> <tr><td><img src="http://www.runescape.com/img/hiscores/attack.gif"
>> valign="bottom" width=16 height=16 /></td><td>&nbsp;</td><td><a
>> href="hiscoreuser.cgi?username=zezima&category=1"
>> class=c>Attack</a></td><td align="right">4</td><td
>> align="right">99</td><td align="right">53,156,556</td></tr>
>>
>>
>> and I apply preg_match_all:
>>
>> preg_match_all("/(<tr><td><img
>> src=\"http:\/\/www.runescape.com\/img\/hiscores\/attack.gif\"
>> valign=\"bottom\" width=16 height=16 \/><\/td><td>&nbsp;<\/td><td><a
>> href=\"hiscoreuser.cgi\?username=)([\w])+(&category=1\"
>> class=c>Attack<\/a><\/td><td align=\"right\">)([1-9])+(<\/td><td
>> align=\"right\">)([1-9])+(<\/td><td
>> align=\"right\">)([1-9,])+(<\/td><\/tr>)/",$seite,$attack);
>
>
> ...
>
>> But I would expect to get
>> [2] => Array
>> (
>> [0] => zezima
>> )
>> [6] => Array
>> (
>> [0] => 99
>> )
>> [8] => Array
>> (
>> [0] => 53,156,556 )
>>
>> Instead of the values above.
>>
>> Can you explain me how I can get those values?
>
>
> Try something like:
>
> preg_match_all('#username=([^&]+).+<td align="right">\d+</td><td
> align="right">(\d+)</td><td align="right">([\d, ]+)</td>#i', $seite,
> $matches);
>
> print_r($matches);
>
> Not tested - might need tweaking.
>
Now it works! I still use mine, but i put the + directly after the
closing bracket:
([\d]+) instead of ([\d])+

Thanks a lot for your help! I looked at your reg exp and saw this.

Yannick Mortier

 

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

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