Skip to content
Advertisement

How can i take the element name inside the Html

How can i able to find the date format in UTC from the html element 2018-06-14T03:00:00.000Z. I am new in php so i don’t know how to grab it.

<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
      14 Jun 2018 - 18:00
      <span class="fi-mu__info__localtime">Local time</span>
</div>

Advertisement

Answer

You might do it using find for getting the div with classname fi-mu__info__datetime and then getting the data-utcdate:

$data = <<<DATA
<div class="fi-mu__info__datetime" data-utcdate="2018-06-14T03:00:00.000Z">
      14 Jun 2018 - 18:00
      <span class="fi-mu__info__localtime">Local time</span>
</div>
DATA;

$html = str_get_html($data);

foreach($html->find('div[class=fi-mu__info__datetime]') as $element){
    if ($element->hasAttribute("data-utcdate")) {
        echo $element->{"data-utcdate"} . '<br>';
    }
}

If you only want the first one you could use:

echo $html->find('div[class=fi-mu__info__datetime]', 0)->{"data-utcdate"};
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement