简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM