Question

bonjour je suis à la recherche de toutes les instances de balises avec la classe EXACT « bonjour » en utilisant simple_html_dom

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

Ce qui précède ne sont pas tout cela parce que cela me donne aussi des cours comme « bonjour monde ». Il est simple oui à compter dans la liste et l'élément correct du tableau, mais le code source HTML qui est des changements qui est analysé de façon pas pratique.

Toutes les idées comment trouver un terme exact pour la classe?

Merci

Était-ce utile?

La solution

Essayez ceci:

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

Si cela ne fonctionne pas, vous pouvez toujours faire cette approche moins élégante mais en travaillant:

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

    //do stuff here
}

Vous pouvez trouver plus au sujet de ce genre de choses sous la rubrique qui dit Comment trouver des éléments HTML? dans le manuel. Les sélecteurs d'attribut sont très puissants, voir ici:

[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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top