-1

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.

benrules2
  • 417
  • 4
  • 14
  • 1
    what is your goal? you want to replace the value-title? also there is a missing.. –  May 03 '13 at 18:29
  • 1
    I suggest you reading the manual of that library and checking out some tutorials how that works - or take DOMDocument instead. – hakre May 03 '13 at 18:32
  • Fixed span, and my goal is just to read the value-title to a text file... I found the documentation pretty confusing on this, but it looks like I should be using a Dom Document class anyways. – benrules2 May 03 '13 at 18:45

1 Answers1

1

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');
Expedito
  • 7,771
  • 5
  • 30
  • 43