Search code examples
htmltwittersimple-html-dom

html simple dom get date-time vaule


I am trying to get the timestamp of date-time in this html.

<span class="js-short-timestamp js-relative-timestamp"
    data-time="1401528672"
    data-long-form="true">
    15h
  </span>

Using html simple dom how would I get the value "1401528672" from this html. Yes the value/timestamp will change so I need to get value of [date-time] in the html.

Any ideas?

include('simpleHtmlDom/simple_html_dom.php');

$html = file_get_html("https://twitter.com/$user");
//not working
$date = $html->find('span[data-time]->attribute()', 0);
print_r($date);
exit;

Solution

  • Try the below code:

    include('simpleHtmlDom/simple_html_dom.php');
    
    $html = str_get_html('<span class="js-short-timestamp js-relative-timestamp"
        data-time="1401528672"
        data-long-form="true">
        15h
      </span>');
    $data = $html->find('span', 0);
    
    echo $data->attr['data-time'];
    

    @Papa De Beau: I tried the above code using simplehtmldom and it worked :)