PHP Domdocument Get selectors Class Tags Table img Elements

PHP Domdocument Get selectors Class Tags Table img Elements

In this Post We Will Explain About is PHP Domdocument Get selectors Class Tags Table img Elements With Example and Demo.Welcome on – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Like as a PHP DOM multiple class selector and PHP DOM selector id and PHP DOM selector attribute as well as PHP selectorsExample

In this post we will show you Best way to implement php get src from image tag and php get all images from url, hear for PHP DOM selector child and PHP DOM select element with PHP DOM selector classwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

php – Getting DOM elements by classname

$dom = new DOMDocument();
$dom->validateOnParse = true; 
$dom->preserveWhiteSpace = false;
$xpath = new \DOMXpath($dom);
$rows_data  = $xpath->query('//tr[@class="my-class-name"]');

get a complete table with php DOM and print it

$html = "<table ID='liveiddata'><tr><td>test</td><td>Laravel</td></tr><tr><td>PHP</td><td>Angularjs</td></tr><tr><td>Vuejs</td><td>Magento</td></tr></table>";

$mydom = new DOMDocument();
$mydom->validateOnParse = true;

$xpath = new DOMXPath($mydom);
$table_data =$xpath->query("//*[@id='liveiddata']")->item(0);

// for printing simple the dtaa whole html data th and tr and td table just type: 

print $mydom->saveXML($table_data); 
$data_rows = $table_data->getElementsByTagName("tr");
foreach ($data_rows as $my_row) {
  $live_cells = $my_row -> getElementsByTagName('td');
  foreach ($live_cells as $datacel) {
  // print datacel' content as Like as a value
    print $datacel->nodeValue; 

get src from image tag using PHP DOM parse

$u_id = "live24u_";
$postThumbLinks = $xpath->query("//td[@class='cardtable-cardimage']/a");
	 foreach($postThumbLinks as $key=>$data_link) {
        $imgList = $xpath->query("./img", $data_link);
        if($imgList->length > 0) {
            $imageLink = $imgList->item(0)->getAttribute('src');
        echo $data_link->getAttribute('href'), " - ", $data_link->getAttribute('title')," - ", $imageLink, "<br />", PHP_EOL;
		echo "<pre>";
        echo $data_link->getAttribute('href'), PHP_EOL;
		echo "</pre>";
		$url    = $data_link->getAttribute('href');
		$img    = 'Iimages/'.$u_id.'.png';
		$file   = file($url);
		$result = file_put_contents($img, $file);


I hope you have Got What is php – Get Element by ClassName with DOMdocument() Method And how it works.I would Like to have FeadBack From My Blog( readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article( Are Most Always Welcome.