Domanda

ciao sto cercando per tutte le istanze di tag con la classe esatta "ciao" utilizzando simple_html_dom

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

È possibile che questo abbastanza non fare questo perché mi dà anche lezioni di tipo "ciao mondo". E 'semplice sì per contare attraverso ed elencare l'elemento corretto dalla matrice, ma il sorgente HTML che viene analizzato modifiche in modo che non è pratico.

Tutte le idee come trovare un termine esatto per la classe?

Grazie

È stato utile?

Soluzione

Prova questo:

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

Se questo non funziona, si può sempre fare questo approccio meno elegante, ma ancora lavorando:

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

    //do stuff here
}

È possibile trovare maggiori conoscenza di questo genere di cose sotto il titolo che dice Come trovare elementi HTML? nel manuale. I selettori di attributo sono molto potenti, vedere qui:

[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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top