As en exercise to learn php, I'm working on stripping some info from a local events site. One of the fields isn't behaving, and I feel like I'm conceptually off track. Could someone walk through how you'd extract just the time from the following html?
</span>
<span class="dtstart">
<span class="value-title" title="2013-05-03T19:00:00-04:00">
</span>
I've got
foreach($html->find('span[class=dtstart]') as $nested_result){
$start=$nested_result->find('span[class=title].value-title',1);
}
But I think I'm missing something about how the find works.
Any help would be awesome, and I promise this isn't homework! Just trying to make a custom music calendar and learn some php at the same time.
You should use the Dom Document class. Something like the following to initialize it:
$doc = new DOMDocument();
//load HTML string into document object
if ( ! @$doc->loadHTML($html)){
return FALSE;
}
//create XPath object using the document object as the parameter
$xpath = new DOMXPath($doc);
$query = "//span[@class='value-title']";
//XPath queries return a NodeList
$res = $xpath->query($query);
$title = $res->item(0)->getAttribute('title');