simple_html_dom - Sorun kılavuzda yer almayan

1 Cevap php

merhaba ben simple_html_dom kullanarak "merhaba" ÖZDEŞ sınıfı ile etiketlerin tüm örneklerini arıyorum

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

O da bana "merhaba dünya" gibi sınıflar verir çünkü yukarıda oldukça bu yapmaz. Çok basit yoluyla saymak ve diziden doğru elemanı listelemek için evet ama bu pratik değil bu yüzden değişiklikleri ayrıştırılır ediliyor kaynak html.

Herhangi bir sınıf için tam bir terim bulmak için nasıl bir fikir?

Teşekkürler

1 Cevap

Bu deneyin:

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

Bu işe yaramazsa, her zaman bu daha az zarif ama hala çalışıyor yaklaşım yapabiliriz:

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

    //do stuff here
}

Sen How to find HTML elements? kılavuzda diyor başlığı altında şeyler bu tür hakkında daha fazla bilgi bulabilirsiniz. Özellik seçiciler çok güçlü, buraya bakın:

[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.