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