PHP
  Home arrow PHP arrow Handling HTML Strings and Files with t...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Handling HTML Strings and Files with the DOM XML Extension in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-03-25

    Table of Contents:
  • Handling HTML Strings and Files with the DOM XML Extension in PHP 5
  • Loading HTML code from a specific string with the loadHTML() method
  • Reading contents from HTML files with the loadHTMLFile() method
  • Building HTML files from their DOM representation with the saveHTMLFile() method

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Handling HTML Strings and Files with the DOM XML Extension in PHP 5
    (Page 1 of 4 )

    The DOM XML extension has a few additional methods that can be used to process HTML files and strings, at least at a pretty basic level. Thus, this fifth part of the series will be entirely focused on explaining how to work with these methods. I will include some illustrative code samples.

    Working on XML documents with PHP can be quite a challenging task, since this process often involves reading data from remote files, parsing specific nodes, inserting and removing elements from the document tree, and so forth. However, if you’re just about to tackle the development of a web application that requires thorough processing of XML data, there’s no need to start pulling your hair because PHP comes equipped with a helpful extension, called DOM XML, which can be used to parse XML documents in all sorts of clever ways using the API of the Document Object Model.

    Understanding how to use the methods and properties provided by this library requires a little effort from you, despite its fairly easy learning curve. Therefore, if you’re looking for a comprehensive guide on how to get the most out of this powerful XML-related PHP extension, then you should take a closer look at this article series. In doing so, you’ll hopefully learn a few useful things, such as creating XML documents from scratch, appending, copying, and removing nodes, and even processing HTML strings by way of their DOM representation. What else can you ask for?

    Now that you’re well aware of the topics that are treated in this series of articles, let me quickly review the items that were discussed in the last tutorial. This way you’ll be able to have clearer idea about how they can be linked with the ones I plan to cover in this article.

    Throughout the course of the preceding tutorial I explained how to access multiple nodes of a specific XML document using the “getElementsByTagName()” method, which presents practically the same functionality as the one utilized to parse web pages with JavaScript. In addition, I demonstrated how to read XML data from an existing text file via the “load()” method. And finally, I demonstrated how to read XML strings by way of a similar method, called “loadXML()”.

    As you can see, the DOM XML extension has plenty of options when it comes to moving portions of an XML document (or even the entire document) from one place to another. This is certainly a process that can be performed with minor hassles by utilizing the intuitive DOM API mentioned in the beginning.

    So far, so good. At this moment, I'm assuming that you’ve acquired a considerable background in performing some basic operations on simple XML documents through the functionality offered by the DOM XML extension. But what if I tell you that this library permits you to work with data formatted in plain HTML?

    Let’s not waste any more time in preliminaries and continue learning how to work with HTML and the DOM XML library. Let’s get started!

    More PHP Articles
    More By Alejandro Gervasio


       · The DOM XML PHP extension has a few additional methods that can be used to process...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway