You are here: Re: [preg_match_all] Better algorithm? « PHP Programming Language « IT news, forums, messages
Re: [preg_match_all] Better algorithm?

Posted by gosha bine on 06/13/07 08:45

On 12.06.2007 20:37 Gilles Ganault wrote:
> Hello
>
> I need to extract some bits of information from a web page, so
> I used preg_match_all. I was wondering if there's a simpler algorithm,
> or if that's the way it's done:
>
> ===========
> preg_match_all("|$regex|smi",$buffer,$matches,PREG_PATTERN_ORDER);
>
> $elements=sizeof($matches);
> $x=sizeof($matches,TRUE);
> $rows = $x/$elements;
> $rows--; //Why is the last row empty?
>
> print "elements=$elements, x=$x, $rows<br>";
>
> for ($row=0;$row < $rows;$row++){
> $string = "";
> for($element=1;$element < $elements;$element++){
> $string .= $matches[$element][$row] . ",";
> }
> //Remove trailing ","
> $string = trim($string, ",");
> print "$string<hr>";
> }
> ===========
>
> Thank you.

Try using foreach to iterate through your arrays.

--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

 

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

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