Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code will try to find an element with the class of <code>caption</code> <strong><em>within</em></strong> the element with the ID of <code>leadtxt</code>. Since you have an ID, and IDs must be unique, it would make more sense to simply use that:</p> <pre><code>$html-&gt;find('#leadtxt', 0) </code></pre> <p>The exact answer to your question would be this:</p> <pre><code>$html-&gt;find('div#leadtxt.caption', 0) </code></pre> <p>Note the lack of space - it'll find the div element with the ID of <code>leadtxt</code> and the class of <code>caption</code>. But again, this is redundant and the above approach would be better and most likely faster.</p> <p><strong>Edit:</strong> here are some further examples as I'm not clear on exactly what you are trying to do.</p> <p>The following would find all elements which have the ID of <code>leadtxt</code> <strong>or</strong> the class of <code>caption</code>:</p> <pre><code>$html-&gt;find('#leadtxt, .caption') // OR specify the fact you only want DIV elements... $html-&gt;find('div#leadtxt, div.caption') </code></pre> <p>This would specify you want elements with ANY of the given classes (one or more):</p> <pre><code>$html-&gt;find('.classone, .classtwo, .classthree') // OR just the DIV elements with any of these classes: $html-&gt;find('div.classone, div.classtwo, div.classthree') </code></pre> <p>This would specify any elements with ALL the given classes:</p> <pre><code>$html-&gt;find('.classone.classtwo.classthree') // OR again, just DIV elements... $html-&gt;find('div.classone.classtwo.classthree') </code></pre> <p><strong>Edit 2:</strong> as you have already said, it seems Simple HTML DOM fails whenever you provide a selector which specifies multiple classes/IDs together. I can only assume that is a weakness in the library which has not yet been addressed. Its a shame, as it means it does <strong>not</strong> work with the standard CSS selectors given above, despite claiming to.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload