How to parse and process HTML/XML using PHP ? Last Updated : 17 Aug, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will learn how to process XML using PHP. We have already learnt the basics of XML and their differences with respect to HTML. Different elements of XML can be learnt from XML Elements to understand the working of the following programs. The simplexml_load_string() function is used to parse the given XML and then the XML object can be used for accessing the XML data. Example 1: The following example reads and prints the given XML string. HTML <html> <body> <?php /* XML string */ $myXMLData = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>GeeksForGeeks</to> <from>Tom</from> <heading>Submission</heading> <body> Please see my articles of PHP! </body> </note>"; /* The function reads xml data from the passed string */ $xml = simplexml_load_string($myXMLData) or die("Error: Cannot create xml data object"); print_r($xml); ?> </body> </html> Output: SimpleXMLElement Object ( [to] => GeeksForGeeks [from] => Tom [heading] => Submission [body] => Please see my articles of PHP! ) Example 2: The following example demonstrates how to get XML node values using PHP. The node values are shown in the output given below. HTML <!DOCTYPE html> <html> <body> <h2>GeeksForGeeks </h2> <b> Get data from XML data string </b> <br /><br /> <?php // XML string $myXMLData = "<?xml version='1.0' encoding='UTF-8'?> <note> <to>GeeksForGeeks</to> <from>John</from> <heading>Submission</heading> <body>Please see my articles of PHP!</body> </note>"; /* The function reads xml data from the passed string */ $xml = simplexml_load_string($myXMLData) or die("Error: Cannot create xml data object"); echo "To : " . $xml->to . "<br>"; echo "From : " . $xml->from . "<br>"; echo "Subject : " . $xml->heading . "<br>"; echo "Mail : " . $xml->body; ?> </body> </html> Output: Â Comment More infoAdvertise with us Next Article How to parse and process HTML/XML using PHP ? G geetanjali16 Follow Improve Article Tags : PHP HTML-Misc PHP-XML PHP-Misc Similar Reads How to Convert XML data into JSON using PHP ? In this article, we are going to see how to convert XML data into JSON format using PHP. Requirements: XAMPP Server Introduction: PHP stands for hypertext preprocessor, which is used to create dynamic web pages. It also parses the XML and JSON data. XML stands for an extensible markup language in wh 3 min read How to get the source code of a web page using PHP ? Given a webpage, for which we need to find its source code using PHP. For this, we are going to use the PHP htmlspecialchars() function which converts any predefined characters to their subsequent HTML entities.Example 1: Suppose we take a sample website that looks like the below image, let us see w 2 min read How to parse HTML file in PHP ? In this article, we will learn to parse HTML in PHP. What is parsing? Generally parsing is converting one data type to another. It means how we can convert various data types to HTML. For example: Converting string to HTML. Why do we need parsing? To add the dynamic data (HTML content) at a certain 2 min read How to Display HTML Tags as Plain Text using PHP? HTML tags begin with the less-than character and end with greater-than character, the text inside the tag formatted and presented according to the tag used. Every tag has special meaning to the browser but there are cases when to show plain HTML code in webpage. There are various methods in PHP to s 3 min read How to use PHP in HTML ? In this article, we will use PHP in HTML. There are various methods to integrate PHP and HTML, some of them are discussed below. You can add PHP tags to your HTML Page. You simply need to enclose the PHP code with the PHP starts tag <?php and the PHP end tag ?>. The code wrapped between these 2 min read Like