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 = "<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;
$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, "<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);
    }

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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   vuejs Simple calculator web Application
  2.   Class 'PhpParser\Parser\Php7' not found
  3.   BOOTSTRAP ACCORDION WITH PLUS MINUS ICON
  4.   Laravel Pagination Example Tutorial
  5.   PHP GET HTML source code WebPages using DOM Parser
  6.   Laravel 6 Set Active Navigation Menu Example
  7.   How to display image from storage path using route in Laravel?
  8.   Laravel 7 Generate/Create PDF File Tutorial From Scratch
  9.   Magento Create custom Database Table with Module
  10.   Eloquent Left Join Queries in Laravel Examples

Leave a Reply

Your email address will not be published. Required fields are marked *