PHP & XML
XML is a HTML-like markup language. An XML document is plain text and contains tags limited by . There are two major differences between XML and HTML.
- XML does not define a specific set of tags.
- XML really "chooses" the document structure.
XML gives you more privileges than HTML. HTML has a specific set of tags: tags surrounding a link, tags
start a paragraph . However, an XML document can use any tag you want. Place tags around a movie rating, tags around someone's height. Therefore, XML gives you the option to structure your own tags.
XML is quite strict when it comes to document structure. HTML allows you to work quickly and fairly softly with open and closed tags. But XML is not like that.
The following HTML list is considered invalid in XML:
HTML là ngôn ngữ đánh dấu văn bản XML cũng là ngôn ngữ đánh dấu văn bản JavacScript không phải ngôn ngữ đánh dấu văn bản
This is an invalid XML document, because there are no closing tags corresponding to 3 open tags
- . Each opening tag in an XML document must have a closing tag.
Valid HTML List in XML must be as follows:
- HTML is a text markup language
- XML is also a text markup language
- JavacScript is not a text markup language
Parsing an XML document
The new SimpleXML module of PHP 5 helps to parse an XML document in a simple and good way. It converts an XML document into an object that provides structured access to XML.
To create a SimpleXML object from an XML document stored in a string, pass this string to the simplexml_load_string () function. It returns an XML object.
For example:
You try the example:
php $note =<<< XML QTM to > Bạn from > Hẹn đi ăn heading > Cuối tuần đi nhậu nhé! body > note > XML ; $xml = simplexml_load_string ( $note ); print_r ( $xml ); ?>
Save the program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php to see the result.
Note - You can use simplexml_load_file (filename) function if you have XML content in a file.
For a complete list of functions related to parse XML documents, you access: Function synthesis in PHP.
Create an XML document
SimpleXML is good to parse existing XML documents, but you can't use it to create a new document.
The easiest way to create an XML document is to build an array in PHP that has a structure that reflects what the XML document is and then traverses the array, printing each element in the appropriate format.
For example
You try the example:
php $channel = array ( 'title' => "Thủ thuật công nghệ" , 'link' => 'https://quantrimang.com/' , 'description' => 'Những thủ thuật công nghệ mới, hay nhất.' ); print "n" ; foreach ( $channel as $element => $content ) { print " <$element>" ; print htmlentities ( $content ); print "n" ; } print "" ; ?>
Save the program in a file named test.php in htdocs , then open the browser and type the address http:/// localhost: 8080 / test.php to see the result.
Follow tutorialspoint
Last lesson: PHP & AJAX
Next lesson: Object-oriented programming in PHP
May be interested
- Check out the 'buffalo' Pokémon in Pokémon Goeach type of pokemon has hp, cp, ability to attack and endure differently. based on these indicators, players can determine as well as choosing the most powerful pokemon for their offensive tactics.
- Sitting home can also locate Pokemon around, do you believe it?the tightening of the niantic developers' rules to prevent players from abusing the support tools also brings annoyance, such as those who have no conditions to move much, go away, it is hard to know. get the location of the pokemon around the area they live in
- 5 undeniable benefits when playing Pokemon Goget to know many new people, breathe fresh air, relieve stress, increase concentration thanks to going out for a walk .... are compelling reasons to force you to try pokemon go now .
- Want to earn the fastest Pokécoins in Pokémon Go? So don't miss this article!pokécoins in pokémon go play the role of buying items in the store. the more coins you earn, the more likely you are to buy more items. to earn pokécoins, players will have to complete certain tasks or buy real money.
- Pokémon systems when fighting in Pokémon Goeach pokémon system in pokémon go has different strengths, along with a specific weakness. this type of pokémon will have the power to attack the other pokémon, but can defeat the other pokémon. if you know the characteristics of each type, it will be easier to choose which pokémon to battle.
- The terms you need to know when playing Pokémon Gopokémon go is the most prominent name in recent days. this game of capturing and training virtual animals has created a relatively new way of playing, as players have to constantly move to catch pokémon. during the process of joining pokémon go, you will encounter and use a lot of important terms. so what do they mean?
- How to play Pokemon GO on Windows computersrecently, pokemon go has become a popular game, attracting thousands of gamers around the world. in previous posts network administrator has guided you on how to play pokemon go on android devices and ios devices. in the article below, network administrator will guide you how to play pokemon go on windows computers using bluestacks emulator software.
- How to become a good Pokémon Go hunter?with a new way of playing, pokémon go has created a new phenomenon in the game village around the world. players will have to go around and find pokémon for themselves. so how to quickly catch pokémon and in large numbers?
- Things to know to upgrade Pokémon in Pokémon Gothe whirlwind pokémon go has spread its power right on the first day of its release. everyone rushed to the street to find a pokémon for themselves. therefore, in order to become a pokémon hunter, you need to master the basics of participating in pokémon go battlefield.
- List of medals received in Pokemon Goin addition to getting items when leveling up, gamers who join pokemon go also have the opportunity to receive their proud achievements.