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 Pakainfo.com – 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();
libxml_use_internal_errors(true);
$dom->validateOnParse = true; 
$dom->loadHTML($content);       
$dom->preserveWhiteSpace = false;
$xpath = new \DOMXpath($dom);
$rows_data  = $xpath->query('//tr[@class="my-class-name"]');
var_dump($rows_data);

get a complete table with php DOM and print it

$html = "
testLaravel
PHPAngularjs
VuejsMagento
"; $mydom = new DOMDocument(); $mydom->validateOnParse = true; $mydom->loadHTML($html); $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, "
", PHP_EOL; echo "
";
        echo $data_link->getAttribute('href'), PHP_EOL;
		echo "

";

$url = $data_link->getAttribute('href');
$img = 'Iimages/'.$u_id.'.png';
$file = file($url);
$result = file_put_contents($img, $file);
}

Example

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(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Comment