Simple HTML DOM wildcard in attribute
attributes, php, simple-html-dom, wildcard
Solution
Since Simple HTML DOM does already have a method for selecting attributes that contain a certain value and|or something else. For example
`$html->find("div[class*=col]", 0)->outertext`
Or you could just retrieve `div` nodes that start with `col` like so
`$html->find("div[class^=col]", 0)->outertext`
And for safe keeping you can find all the other ways to filter attributes in this 3rd party plugin (By the way there are way better things for dealing with DOM that are based on `libxml`, a definitive list can be found here)
- `[attribute]` - Matches elements that have the specified attribute.
- `[!attribute]` - Matches elements that don't 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.
Source: http://simplehtmldom.sourceforge.net/manual.htm
Problem
I have the following tags ``` <div class="col *">Text</div> ``` `*` is anything. I want to get all div tag with class attribute contains `col` (as in my example) using Simple HTML DOM.