Search code examples
phpsimple-html-dom

Simple HTML DOM get value "data-url" from <div> tag


I'm trying to get the value from "data-url" from tags like this:

<div class="event event-list " data-id="24692" data-url="https://www.example.com/events/20-01-2017-event-x/">

this code is not working:

$urlVariable =  ('https://www.example.com/');

$html           = file_get_html($urlVariable);

foreach($html->find('[data-url]') as $detailLinks)                                              
print $detailLinks . '<br>';    

any help would be greatly appreciated.


Solution

  • You find div with data-url attribute

    foreach($html->find('div[data-url]') as $detailLinks) 
       echo $detailLinks->{'data-url'};