Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting div by class with PHP DOM
    text
    copied!<p>The problem is retrieving and displaying the div contents. Catch is, it's with a multiclass:</p> <pre><code>&lt;li class="activity user-generated" id="activity:153411947-kIq0nOFam0hE68sL6P298_DIo4s-1386284074745"&gt; </code></pre> <p>I probably could've worked with it easier if the ID doesn't automatically generate for each new status, in my case.</p> <p>Also, on this topic, is it possible to get each tag and list them in order? </p> <p>Thanks for your time.</p> <pre><code>$classname = "activity"; $domdocument = new DOMDocument(); $domdocument-&gt;loadHTML($doc); $a = new DOMXPath($domdocument); $spans = $a-&gt;query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]"); </code></pre> <p>with $doc being the page I'm loading</p> <p>Alright, let me restart this, since the fact this isn't working is bugging me greatly.</p> <p>What I'm trying to do is read from the element I've posted, <em>but</em> I need to call it from a URL, as reading just the element itself as HTML is fine. From a URL, I get a bunch of unnecessary errors, basically repeating the same thing.</p> <pre><code>Function obtainUserStatus($Username){ $DOM = new DOMDocument(); $Class = "activity"; $DOM-&gt;loadHTMLFile('http://lifestream.aol.com/stream/' . $Username); $X = new DOMXPath($DOM); $ID = $X-&gt;query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $Class ')]")-&gt;item(0)-&gt;getAttribute('id'); Echo $ID; } </code></pre> <p>Which just returns the errors.</p> <p>I need to return the div's content from the class (or the ID, which I'm doing from there -- no big deal.) </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