php: php simple dom parser question
i开发者_如何学运维'm using the php simple dom parser and found a little issue:
when the selector returns only one element, i also need to run a foreach loop for it. is there a simpler way to do it?
thanks
The manual says
find()
has a second parameter for exactly that:
mixed find ( string $selector [, int $index] )
Find elements by the CSS selector. Returns the Nth element object if index is set, otherwise return an array of object.
So in your case,
$txt = $ctl->find("input", 0);
should do the job.
SimpleHTMLDOM API reference
精彩评论