Book Image

Object-Oriented Programming with PHP5

By : Hasin Hayder
Book Image

Object-Oriented Programming with PHP5

By: Hasin Hayder

Overview of this book

<p>Some basic objected-oriented features were added to PHP3; with PHP5 full support for object-oriented programming was added to PHP. Object-oriented programming was basically introduced to ease the development process as well as reduce the time of development by reducing the amount of code needed. OOP can greatly improve the performance of a properly planned and designed program.</p> <p>This book covers all the general concepts of OOP then shows you how to make use of OOP in PHP5, with the aid of an ample number of examples.</p>
Table of Contents (15 chapters)
Object-Oriented Programming with PHP5
Credits
About the Author
About the Reviewers
Introduction
Index

Modifying Existing Documents


DOM API helps to create XML document easily as well as provide easy access to load and modify existing documents. With the following XML we will load the file we just created a few minutes ago and then we will change the header test of the first h1 object:

<?php

 $uri = 'c:/abc.xml';
 $document = new DOMDocument();
 $document->loadHTMLFile($uri);// load the content of this URL as HTML
 $h1s = $document->getElementsByTagName("h1");//find all h1 elements
 $newText = $document->createElement("h1","New Heading");//created a 
                                                  //new h1 element
 $h1s->item(0)->parentNode->insertBefore($newText,
 $h1s->item(0));//insert before the existing h1 element
 $h1s->item(0)->parentNode->removeChild($h1s->item(1));//remove the 
                                                   //old h1 element
 echo $document->saveHTML();//display the content as HTML

?>

The output is shown below:

&lt...