开发者

Using Simple_Html_Dom Find Function PHP

开发者 https://www.devze.com 2022-12-27 07:17 出处:网络
for a while I\'ve been using the simple_html_dom include, but I have a question. with the find function, i\'ve been using

for a while I've been using the simple_html_dom include, but I have a question.

with the find function, i've been using

$something->find('table[class="class_name"]', 0);

and things like that, but I don't know how to specify two things, like

$something->find('table[class="class_name开发者_运维知识库"][bgcolor="#ffffff"]', 0);

How would that work? (that example doesn't work)


It appears that you're being specific in the wrong ways with the find function. If you're familiar with CSS and DOM best practices, then the more natural way to select the element you're looking for should more instinctively be:

$tableElements = $domParent->find('table.className');

It takes advantage of the fact that classes denote DOM objects with simliar properties, particularly for the front end. In fact, looking for all tables with a particular background color is working backwards from the way the problem is appropriately perceived.

Note that you can have multiple classes on DOM objects. If you're looking for a sub-group of tables that share some front-end attribute, your CSS should reflect this by assigning, for instance, the background color attribute to a separate class shared by these tables. Then you'll be able to use the above code snippet specifying for the more specific class to get the elements you're looking for.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号