1676672640
In this article, we will see to fixed class "DOMDocument" not found in laravel. Also, class 'domdocument' not found php 7, and class 'domdocument' not found php 8. class 'domdocument' not found php artisan. The DOMDocument class represents an entire HTML or XML document.
Also, we will see how to install php-dom and php-xml extensions in ubuntu using the terminal.
So, let's see fixed: class "DOMDocument" not found in laravel, class domdocument not found in laravel, class 'domdocument' not found laravel 9, class 'domdocument' not found ubuntu and how to resolve domdocument class not found in php.
Run the following command to install php-dom and php-xml.
sudo apt-get install php-dom
sudo apt-get install php-xml
Install php-dom in PHP 8.2
Run the following command and install php8.2-dom and php8.2-xml.
sudo apt-get install php8.2-dom
sudo apt-get install php8.2-xml
Install php-dom in PHP 8.1
Run the following command and install php8.1-dom and php8.1-xml.
sudo apt-get install php8.1-dom
sudo apt-get install php8.1-xml
Install php-dom in PHP 8.0
Run the following command and install php8.0-dom and php8.0-xml.
sudo apt-get install php8.0-dom
sudo apt-get install php8.0-xml
Install php-dom in PHP 7.4
Run the following command and install php7.4-dom and php7.4-xml.
sudo apt-get install php7.4-dom
sudo apt-get install php7.4-xml
Install php-dom in PHP 7.3
Run the following command and install php7.3-dom and php7.2-xml.
sudo apt-get install php7.2-dom
sudo apt-get install php7.2-xml
Install php-dom in PHP 7.2
Run the following command and install php7.2-dom and php7.2-xml.
sudo apt-get install php7.2-dom
sudo apt-get install php7.2-xml
Original article source at: https://websolutionstuff.com/
#laravel #class #dom #document
1676672640
In this article, we will see to fixed class "DOMDocument" not found in laravel. Also, class 'domdocument' not found php 7, and class 'domdocument' not found php 8. class 'domdocument' not found php artisan. The DOMDocument class represents an entire HTML or XML document.
Also, we will see how to install php-dom and php-xml extensions in ubuntu using the terminal.
So, let's see fixed: class "DOMDocument" not found in laravel, class domdocument not found in laravel, class 'domdocument' not found laravel 9, class 'domdocument' not found ubuntu and how to resolve domdocument class not found in php.
Run the following command to install php-dom and php-xml.
sudo apt-get install php-dom
sudo apt-get install php-xml
Install php-dom in PHP 8.2
Run the following command and install php8.2-dom and php8.2-xml.
sudo apt-get install php8.2-dom
sudo apt-get install php8.2-xml
Install php-dom in PHP 8.1
Run the following command and install php8.1-dom and php8.1-xml.
sudo apt-get install php8.1-dom
sudo apt-get install php8.1-xml
Install php-dom in PHP 8.0
Run the following command and install php8.0-dom and php8.0-xml.
sudo apt-get install php8.0-dom
sudo apt-get install php8.0-xml
Install php-dom in PHP 7.4
Run the following command and install php7.4-dom and php7.4-xml.
sudo apt-get install php7.4-dom
sudo apt-get install php7.4-xml
Install php-dom in PHP 7.3
Run the following command and install php7.3-dom and php7.2-xml.
sudo apt-get install php7.2-dom
sudo apt-get install php7.2-xml
Install php-dom in PHP 7.2
Run the following command and install php7.2-dom and php7.2-xml.
sudo apt-get install php7.2-dom
sudo apt-get install php7.2-xml
Original article source at: https://websolutionstuff.com/
1625647440
How to parse HTML documents using PHP’s native DOM classes - useful for web scraping and manipulating website HTML outputs.
Example code: https://github.com/iabhinavr/tutorials
#php #html #domdocument
1596096960
DOM DOCUMENT PHP
27th July 2020
4 mins read
Sometimes there might arise a situation to alter the stored HTML of the database to display on the fly to the user or you might want to play around with XML from PHP. This is where the **DOMDocument**
of PHP comes to place.
NOTE: No need for any external libraries. It’s built-in hidden gem of PHP.
We will be covering the following topics
Basically, I faced the problem when writing code for the existing blog to AMP version blog.
I had my articles code snippets, images, iframes, and other HTML elements stored inside the database. These HTML elements are not directly compatible with AMP HTML and have to be replaced, common tags that I had to replace are as follows
img -> amp-img
iframe -> amp-iframe
Not only elements even a few **attributes**
of HTML elements were not supported.
I was earlier working on WYSIWYG editors and stumbled upon PHP’s hidden gem ie, DomDocument.
DomDocument object is similar to that of your Javascript DOM. In case if you have earlier worked with Javascript DOM manipulation then it will be really simpler for you.
DOMDocument()
)You can start playing around with PHP DOMDocument by initializing it as follows
$dom = new \DOMDocument();
loadHtml
/ loadXml
)Now, we have to load the HTML or XML document we would like to playaround.
#html
1551164735
I have some HTML content like this
<p><b style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Lato, Arial, Helvetica, sans-serif; vertical-align: baseline; color: rgb(89, 89, 89);">'60 Degrees South Bar and Grill'</b><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> is an imaginative and quirky space that allows diners to enjoy the sea breeze and spectacular views of the Indian Ocean from three terraces. The bar and Grill is ideally situated in </span> <b style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Lato, Arial, Helvetica, sans-serif; vertical-align: baseline; color: rgb(89, 89, 89);">Stone Town</b><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> on the Shangani strip, perfect for a 'sundowner' while watching a breathtaking sunset. Choose from a glass of wine from their international selection or a </span> <p><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> <img alt="" src="https://green.com/files/images/Restaurants/60%20Degrees%20South-2.jpg" style="width: 550px; height: 491px;"></span></p> <p><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> <img alt="" src="https://green.com/files/images/Restaurants/60%20Degrees%20South-2.jpg" style="width: 550px; height: 491px;"></span> </p>
I want to replace all img
tag with a
tag i am using PHP DOMDocument
.
$dom = new DOMDocument(); $dom->loadHTML($content); foreach ($dom->getElementsByTagName('img') as $img) { $src = urldecode($img->getAttribute('src')); if (!empty($src)) { $link = $dom->createElement('a', "Image"); $link->setAttribute('target', '_blank'); $link->setAttribute('href', $src); $img->parentNode->replaceChild($link, $img); } } $dom->saveHTML();
This code will only replace only first img
. How can i replace all img
to a
tag.
this is the output i am getting
<p><b style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Lato, Arial, Helvetica, sans-serif; vertical-align: baseline; color: rgb(89, 89, 89);">'60 Degrees South Bar and Grill'</b><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> is an imaginative and quirky space that allows diners to enjoy the sea breeze and spectacular views of the Indian Ocean from three terraces. The bar and Grill is ideally situated in </span> <b style="margin: 0px; padding: 0px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Lato, Arial, Helvetica, sans-serif; vertical-align: baseline; color: rgb(89, 89, 89);">Stone Town</b><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> on the Shangani strip, perfect for a 'sundowner' while watching a breathtaking sunset. Choose from a glass of wine from their international selection or a </span> <p><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> <a target="_blank" href="https://green.com/files/images/Restaurants/60%20Degrees%20South-1.jpg">Image</a></span></p> <p><span style="color: rgb(89, 89, 89); font-family: Lato, Arial, Helvetica, sans-serif;"> <img alt="" src="https://green.com/files/images/Restaurants/60%20Degrees%20South-2.jpg" style="width: 550px; height: 491px;"></span> </p>
#php #html
1622692500
How to parse HTML documents using PHP’s native DOM classes - useful for web scraping and manipulating website HTML outputs.
Example code: https://github.com/iabhinavr/tutorials
#php #html