質問

こんにちは、私はsimple_html_domを使用して「ハロー」EXACTクラスとタグのすべてのインスタンスを探しています。

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