How can I get data attributes with php?

125
October 18, 2018, at 4:30 PM

Currently I am using this code.

$html = file_get_html($url);
$file = $html->find('audio'); 
$data['download'] = $file->attr['data-file'];

to try and gather the data from here.

<div class="actions clearfix">
  <div class="player clearfix">
      <div class="player-init preload" data-file="http://example.com/mp3embed-cegoq1gcnrj6.mp3"></div>
  </div>
 </div>

My code from above is not working, for some reason.

Answer 1

Please tried below code.

$url = 'https://somedomain.com/somesite/';
$content = file_get_contents($url);
$first_step = explode( '<div class="player-init preload" data-file="' , $content );
$data['download'] = explode('"></div>' , $first_step[1] );
echo $data['download'];
exit;
Answer 2

May be Something like this will work.

$DOM = new DOMDocument;
$DOM->loadHTML($html);
$xpath = new DOMXpath($DOM);
$items = $xpath->query("//div[contains(@class,'player-init')]");
$mydata = $items->documentElement->getAttribute('data-file');
Rent Charter Buses Company
READ ALSO
mysql_real_escape_string returned slash

mysql_real_escape_string returned slash

I am using mysql_real_escape_string on my code and the data on the form is:

115
php to mysql update query isnt running properly

php to mysql update query isnt running properly

I have been trying to create an update function for my database and have been stuck for days on this now so thought that I would ask for helpThe code seems to run without issues and no errors are being reported but it isn't being updated

122
mcrypt_encrypt openssl_encrypt compatibility problem

mcrypt_encrypt openssl_encrypt compatibility problem

I share encrypted data with an external providerThe provider gives me the algo where the input string needs to be padded with blanks into 16byte blocks, i

164
How to insert array of data in to mysql database in PHP?

How to insert array of data in to mysql database in PHP?

My problem is that an array of data is not inserted to the database only last data is insertedSo, how to insert whole data at a time after click save button? I am using Codeigniter framework

121