PHP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

<html> <head> <title> Top 20 Songs </title> </head> <body> <?

php function get_content($URL){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch,CURLOPT_PROXY,"http://proxy.ssn.net:8080"); curl_setopt($ch, CURLOPT_URL, $URL); $data = curl_exec($ch); curl_close($ch); return $data; } // Create connection $con=mysqli_connect("","root","lenovo","test"); // Check connection if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $page = get_content('http://www.radiomirchi.com/more/tamil-top-20/'); // new dom object $dom = new DOMDocument; //load the html @$html = $dom->loadHTML($page); //discard white space $dom->preserveWhiteSpace = true; echo "<table>"; $xpath = new DOMXPath($dom); $elements = $xpath->query('//span[@class="maroon12N"]'); preg_match_all("/<span class=\"orange11n\">(.*?)<\/span>/", $page, $movies); $rowNumber = 1; $index=0; if (!is_null($elements)) { foreach ($elements as $element) { echo "<tr>"; echo "<td> $rowNumber </td>"; echo " "; echo "<td> $element->nodeValue </td>"; echo " "; $movie=$movies[1][$index]; echo "<td> $movie </td>"; echo " "; $cmpne=$movies[1][$index+1]; echo "<td> $cmpne </td> ";

echo "</tr>"; echo "\n"; $index=$index+6; mysqli_query($con,"INSERT INTO songs VALUES (NOW(),'$rowNumber','$element>nodeValue','$movie','$cmpne')"); $rowNumber++; } } ?> </body> </html> create table songs( day timestamp, position integer, name varchar(100), movie varchar(100), cmpne varchar(50) );

You might also like