- SimpleXML
-
A new PHP 5-only extension that excels at parsing RSS files, REST results, and configuration data. If you know the document's format ahead of time, SimpleXML is the way to go. However, SimpleXML supports only a subset of the XML specification.
- XPath
-
This extension allows you to query XML documents like you're searching a database, to find the subset of information that you need and eliminate the unnecessary portions.XSLT
-
Reading XML into a tree
-
Reading XML from a stream
-
Creating new XML documents
-
Searching XML with XPath
-
Changing XML into HTML or other output formats with XSLT
-
Validating XML to ensure it conforms to a specification
Example XML address book
<?xml version="1.0"?> <address-book> <person id="1"> <!--Rasmus Lerdorf--> <firstname>Rasmus</firstname> <lastname>Lerdorf</lastname> <city>Sunnyvale</city> <state>CA</state> <email>rasmus@php.net</email> </person> <person id="2"> <!--Zeev Suraski--> <firstname>Zeev</firstname> <lastname>Suraski</lastname> <city>Tel Aviv</city> <state></state> <email>zeev@php.net</email> </person> </address-book>
$dom = new DOMDocument; $dom->preserveWhiteSpace = false; $dom->load('address-book.xml'); $root = $dom->documentElement; foreach ($root->childNodes as $person) { process($person); }
The childNodes attribute is not an array, but a DOMNodeList object. The item( ) method allows you to access individual items, and the length property tells you the number of items in the list.This code is equivalent to the foreach loop:$people = $root->childNodes; for ($i = 0; $i < $people->length; $i++) { process($people->item($i)); }
XML Extensions in PHP 5
PMA04:40
Categories: PHP
Related Posts:
Get mail info with IMAP or POP3 To read mail using IMAP or POP3, which allows you to create a web-based email client. Use PHP's IMAP extension, which speaks both IMAP and POP3: // open IMAP connection $mail = imap_open('{mail.server.com:143}', &nb… Read More
Displaying Browser Specific-php However, having seen some of the possible values of HTTP_USER_AGENT in the last chapter, you can imagine that there are hundreds of slightly different values. So it's time to learn some basic pattern matching.You'l… Read More
PHP identical operator === Variable types are also important in comparison.When you compare two variableswith the identical operator (===), like this, the active types for the zvals are compared,and if they are different, the comparison fails outright… Read More
Php session Info and cookies #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WI… Read More
php -Mail Functions The mail() function requires an installed and working email subsystem for sending mail. The program to be used is defined by configuration directives in the php.ini file. A common pitfall is that these are not set up cor… Read More
php-use the header() function-php An HTTP (HyperText Transfer Protocol) header is used to send information back and forth between the server and the client (the Web browser). Normally this information is in the form of HTML, which is why the address for Web … Read More
difference between print and echo - php print( ) is a function, echo is a language construct. This means that print( ) returns a value, while echo doesn't. You can include print( ) but not echo in larger expressions. echo is run very fast than … Read More
PHP-Renaming Files and Directories Renaming Files and Directories There are a few useful file and directory functions built-in to PHP which I'll cover in brief here. They include renaming and deleting files as well as listing files located in a… Read More
php Sessions page Php Sessions are used to help maintain the values of variables across multiple web pages. This is done by creating a unique session ID that is sent to the client browser. The browser then sends the unique ID back on eac… Read More
The $_REQUEST Variable-php PHP is a lot more than a way to work with text. You’ve been working with strings non-stop, but there are a lot more types of information you’ll need to work with in your PHP scripts. As you might expect, there are all kinds … Read More
Third-party Cookies Third-party Cookies Third-party cookies come from other domain sources that have items, such as ads or images, embedded on the page adjust cookie and site data permissions. Manage your cookies and site data - chrome … Read More
Creating a Simple Php Functions #menu111 { BORDER-RIGHT: #cccccc 1px dashed; PADDING-RIGHT: 20px; BORDER-TOP: #cccccc 1px dashed; PADDING-LEFT: 20px; BACKGROUND: #dddddd; LEFT: 20px; PADDING-BOTTOM: 20px; MARGIN: 0px; BORDER-LEFT: #cccccc 1px dashed; WID… Read More
Php tutorial - imagemagick Php tutorial - imagemagick Php tutorial - imagemagick - create, edit and compose bitmap imagemagick is free software to create, edit, and compose bitmap images in many formats from the commandline or via progra… Read More
Adding CSS style in php script <?php echo '<span style="font-size:10px">'; // add styles as style attribute echo 'test'; &nbs… Read More
Send Email from a PHP Script you use the mail() function (in combination with a web form in particular), make sure you check it is called from the desired page and protect the form with a CAPTCHA mail(to,subject,message,headers,parameters); <?php… Read More