سؤال

مرحبا، أنا أبحث عن كافة مثيلات العلامات مع الطبقة الدقيقة "Hello" باستخدام Simple_html_dom

foreach($html->find('.hello')as $found

ما سبق لا يفعل ذلك تماما لأنه يعطيني أيضا فصول مثل "Hello World". انها بسيطة نعم للعناية والعناصر الصحيحة في القائمة الصحيحة من الصفيف ولكن المصدر HTML الذي يجري تحليل التغييرات حتى لا يكون ذلك عمليا.

أي أفكار كيفية العثور على مصطلح دقيق للفئة؟

شكرًا

هل كانت مفيدة؟

المحلول

جرب هذا:

foreach($html->find('[class=hello]') as $found)

إذا لم ينجح ذلك، فيمكنك دائما القيام بذلك نهج العمل الأقل أنيقا ولكنه لا يزال:

foreach($html->find('.hello') as $found)
{
    if ($found->class != 'hello')
        continue;

    //do stuff here
}

يمكنك العثور على المزيد من هذا النوع من الأشياء تحت العنوان الذي يقول كيفية العثور على عناصر HTML؟ في الدليل. محددات السمة قوية جدا، انظر هنا:

[attribute]           Matches elements that have the specified attribute.
[attribute=value]    Matches elements that have the specified attribute with a certain value.
[attribute!=value]  Matches elements that don't have the specified attribute with a certain value.
[attribute^=value]  Matches elements that have the specified attribute and it starts with a certain value.
[attribute$=value]  Matches elements that have the specified attribute and it ends with a certain value.
[attribute*=value]  Matches elements that have the specified attribute and it contains a certain value.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top