News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

James Morris' Blog:
Parsing HTML with DOMDocument and DOMXPathQuery
June 27, 2012 @ 10:19:35

In the latest post to his blog James Morris looks at using XPath's query() function to locate pieces of data in your XML.

The other day I needed to do some html scraping to trim out some repeated data stuck inside nested divs and produce a simplified array of said data. My first port of call was SimpleXML which I have used many times. However this time, the son of a bitch just wouldn't work with me and kept on throwing up parsing errors. I lost my patience with it and decided to give DomDocument and DOMXpath a go which I'd heard of but never used.

He includes a code (and XML document) example showing how to extract out some content from an HTML structure - grabbing each of the images from inside a div and associating them with their description content.

0 comments voice your opinion now!
dom domdocument domxpath xpath tutorial html


PHPMaster.com:
PHP DOM Using XPath
June 26, 2012 @ 08:16:08

On PHPMaster.com today there's a new tutorial showing you how to use the XPath functionality that's built into PHP's DOM functionality to query your XML.

In a recent article I discussed PHP's implementation of the DOM and introduced various functions to pull data from and manipulate an XML structure. I also briefly mentioned XPath, but didn't have much space to discuss it. In this article, we'll look closer at XPath, how it functions, and how it is implemented in PHP. You'll find that XPath can greatly reduce the amount of code you have to write to query and filter XML data, and will often yield better performance as well.

They start with some basic XPath queries to find a simple path and locating the record for a specific book. There's also an example of using XPath versus the "find" functions in the DOM functionality (like getElementsByTagName). There's also a bit close to the end about using functions in XPath and how you can pull back in PHP functionality and use native PHP functions in your XPath queries.

0 comments voice your opinion now!
xpath tutorial dom introduction


PHPMaster.com:
PHP DOM Working with XML
June 08, 2012 @ 08:27:45

On PHPMaster.com there's a new tutorial posted about using XML in PHP, an introduction to using the DOM functionality in PHP to work with your XML content.

PimpleXML allows you to quickly and easily work with XML documents, and in the majority of cases SimpleXML is sufficient. But if you're working with XML in any serious capacity, you'll eventually need a feature that isn't supported by SimpleXML, and that's where the PHP DOM (Document Object Model) comes in.

He starts with a brief introduction to XML and DTDs including an example of each (defining a sample book information he'll use in the rest of the tutorial). He helps you create a simple class that takes in the XML content, working with construction/destruction of the object and using it to find, add and delete a book by things like ISBN or genre.

0 comments voice your opinion now!
dom tutorial introduction xml


PHPBuilder.com:
PHP Simple HTML DOM Parser Editing HTML Elements in PHP
September 08, 2011 @ 10:06:07

On PHPBuilder.com today there's a new tutorial from Vojislav Janjic about using a simple DOM parser in PHP to edit the markup even if it's not correctly W3C-formatted - the Simple HTML DOM Parser

Simple HTML DOM parser is a PHP 5+ class which helps you manipulate HTML elements. The class is not limited to valid HTML; it can also work with HTML code that did not pass W3C validation. Document objects can be found using selectors, similar to those in jQuery. You can find elements by ids, classes, tags, and much more. DOM elements can also be added, deleted or altered.

They help you get started using the parser, passing in the HTML content to be handled (either directly via a string or loading a file) and locating elements in the document either by ID, class or tag. Selectors similar to those in CSS are available. Finally, they show how to find an object and update its contents, either by adding more HTML inside or by appending a new object after it.

0 comments voice your opinion now!
simple html dom parse tutorial selector find replace edit


PHPBuilder.com:
Parsing XML with the DOM Extension for PHP 5
October 28, 2010 @ 14:47:56

On PHPBuilder.com there's a new tutorial from Octavia Anghel about using the DOM extension to parse XML in a PHP5 application. The DOM functionality makes it simpler than even the older PHP4 DOM functionality to work with XML messaging and documents.

DOM (Document Object Model) is a W3C standard based on a set of interfaces, which can be used to represent an XML or HTML document as a tree of objects. A DOM tree defines the logical structure of documents and the way a document is accessed and manipulated. Using DOM, developers create and build XML or HTML documents, navigate their structures, and add, modify, or delete elements and content. The DOM can be used with any programming language, but in this article we will use the DOM extension for PHP 5. This extension is part of the PHP core and doesn't need any installation.

They include both a sample XML file to parse and the code you'll need to pull it in and make a basic DOM object out of it. Also included is some code showing how to pull out certain pieces of information, recurse through a set of XML values, add new nodes to the structure, remove a node and more.

0 comments voice your opinion now!
parse xml dom extension tutorial


Qafoo.com:
Practical PHPUnit Testing XML generation
September 17, 2010 @ 13:51:02

On the Qafoo blog today there's a new post from Tobias Schlitt about a method you can use to unit test methods that generate XML without messing with a lot of extra overhead just to test the results.

Testing classes which generate XML can be a cumbersome work. At least, if you don't know the right tricks to make your life easier. In this article, I will throw some light upon different approaches and show you, how XML generation can be tested quite easily using XPath.

He includes a sample class, qaPersonVisitor, that has methods inside it to create a simple XML documents based on the first and last name data into a DOM element. He sets up the basic test case that creates a simple person - including gender and date of birth - and offer a few different suggestions on handling the check (in PHPUnit tests):

  • the naive way of rebuilding the DOM object and assert that they are equal
  • testing the resulting XML from the DOM object against a pre-generated XML document
  • matching the contents via CSS selectors
  • using the tag matching assertions
  • using XPath in a custom assertion (with short and long uses of it included)
0 comments voice your opinion now!
unittest phpunit xml generation xpath dom


Thomas Weinert's Blog:
Using PHP DOM With XPath
April 13, 2010 @ 13:18:32

Thomas Weinert has a recent post to his blog showing how to use one of the more powerful XML-handling features that PHP's DOM extension includes - XPath.

Often I hear people say "We use SimpleXML, because DOM is so noisy and complex". Well, I don't think so. This article explains how you can parse a XML (an Atom feed) using the PHP DOM extension. No other libraries are involved.

In his example he loads an external feed (his own) into a DOM object, blocks any errors with a few handy functions and creates a DOMXPath object on the DOM object to get ready for his queries. He shows how to make searches for titles, subtitles, looping over attributes and an element list returned from one of the first queries. A full code listing is also provided to show how it all fits together.

0 comments voice your opinion now!
dom xpath domxpath tutorial search atom


Matthew Turland's Blog:
Renaming a DOMNode in PHP
February 10, 2010 @ 09:16:58

Matthew Turland has a new post to his blog sharing a handy trick if you've ever looked for a way to use the DOM functionality on PHP to rename a certain node in an XML document. Since the node_name is read-only, some trickery is required.

A recent work assignment had me using PHP to pull HTML data into a DOMDocument instance and renaming some elements, such as b to strong or i to em. As it turns out, renaming elements using the DOM extension is rather tedious.

His method isn't so much of an update of what's already there as it is to replicate the attributes and child nodes of the node you're targeting and pus those back into the document with a call to replaceChild on the parent.

0 comments voice your opinion now!
rename dom xml node tutorial


Zend Developer Zone:
PHP DOM XML extension encoding processing
September 02, 2009 @ 09:48:18

On the Zend Developer Zone today Alexander Veremyev shares some helpful hints he discovered about the DOM XML extension for PHP that could come in handy when working with different character encodings.

I recently worked with PHP's DOM XML extension while working on Zend Framework's Zend_Search_Lucene HTML highlighting capabilities, and uncovered some undocumented features and issues with the extension in regards to character encoding. The information contained in this article should also apply to other libxml-based DOM implementations, as PHP's DOM extension simply wraps that library.

There's five different tips he shares:

  • Internal document encoding is always UTF-8
  • Input data is always treated as UTF-8
  • Text nodes and CDATA are stored as UTF-8 without transformations
  • Document encoding does not affect loading behavior
  • Save/dumping operations and encoding

He describes each of the points and includes some sample code and XML to parse to help illustrate each.

0 comments voice your opinion now!
tutorial dom extension character encoding


Davey Shafik's Blog:
ext/dom and libxml2 charset and entities behaviors
August 11, 2009 @ 10:23:53

Davey Shafik points out a second option for the saveXML function of the DOM functionality in PHP - an option to restrict the use of "empty tags".

This argument currently only supports one value which is the constant LIBXML_NOEMPTYTAGS. This option makes sure that you do not end up with <tag /> but instead, <tag></tag>. This can make things easier if you need more predictable text to perform other changes on later.

He also noticed some other changes that the option made in his XML documents, specifically a size increase issue with spaces. Code samples are included to show these differences.

1 comment voice your opinion now!
dom extension savexml charset libxml2 emptytags


PHPro.org:
Dynamically Create Menu With PHP DOM
July 20, 2009 @ 10:50:52

New from Kevin Waterson on the PHPro.org site is this tutorial looking at dynamically making a website menu with PHP's DOM functionality.

Most PHP coders will have their own menu generation class that will take an array or an item and add it to a HTML un-ordered list or other tag and the styling is handled with CSS. This has proven to be a worthy solution to menu creation, however, PHP already has all the tools and classes built in to create a menu using DOM. It is both powerful and extensible and further eliminates for yet another class in your tree.

The tutorial shows you how to create a simple XML document to define the menu using the DOM functionality in PHP and finally output it as a series of unordered lists that can be styled in whatever way you want.

0 comments voice your opinion now!
xml dom menu dynamic


Content with Style:
Remove nodes in SimpleXMLElement
July 16, 2009 @ 11:15:57

The Content with Style blog has this quick tip on removing nodes from inside of a SimpleXML object without causing problems with its internal handling.

You might think otherwise and hack it with unset(), as it was done in one of the web applications I inherited at work, but today I found out that this works under some conditions, but not with every setup. I'd love to tell you what exactly the differences are that make it break, but I didn't spend the time tracking it down.

Instead, he suggests a call to dom_import_simplexml to swap the object over to the DOM, performing a removeChild on the node and pushing it back over to SimpleXML if the need's there.

0 comments voice your opinion now!
removechild dom tutorial simplexml


Thomas Weinert's Blog:
FluentDOM
June 12, 2009 @ 07:59:13

Thomas Weinert has posted about a new tool he's worked up to make working with the DOM in PHP a bit more fluent - FluentDOM.

Today I like to present a new projekt: FluentDOM. It provides an easy to use, jQuery like, fluent interface for DOMDocument. The idea was born in a workshop of Tobias Schlitt about the PHP XML extensions at the IPC Spring in Berlin.

He includes a basic code example - locating items with an ID of "first" and removing that ID to replace it with a class. If you'd like to check it out (literally) you can grab the latest version from the project's public svn.

0 comments voice your opinion now!
jquery xml dom fluentdom


Stoyan Stefanov's Blog:
Blog-to-podcast with ffmpeg
February 16, 2009 @ 08:45:52

Stoyan Stefanov has an interesting way to "automatically" create podcasts based on your blog posts using PHP, ffmpeg and the "say" command in OS X to create the mp3 result.

ffmpeg is such an amazing tool, looks like it's for video what ImageMagick is for images. An all-powerful all-formats wicked cool command-line tool. This blog post is an introduction to some of the MP3 capabilities of ffmpeg. I'll use ffmpeg to transform a blog post into a podcast-ready mp3 file.

The post shows how to use PHP's DOM functions to grab the title and contents of your post (a simple example, at least) and push that information out to a text file. From there, the "say" command is run on it with the "output" file parameter and the result is sent to ffmpeg for compression into an mp3.

0 comments voice your opinion now!
ffmpeg say osx dom blog podcast convert automatic mp3


PHP in Action:
Get links with XPath
October 07, 2008 @ 08:43:33

In response to this tutorial over on the PHPro.org website a new post has been made to the PHP in Action blog with an "even cooler" way to do the same sort of DOM fetching - XPath.

I'm a little bit surprised at the claim [the tutorial makes] that it's the "correct" (only) way, since there's at least one more that I find even cooler: XPath. Admittedly, it's slower, yet it's a more powerful language.

A quick example is included, building up from a simple search for anchor tags up to a custom query looking for just the anchor tags with a class of "bookmark".

0 comments voice your opinion now!
xpath tutorial dom link find search anchor attribute


PHPPro.org:
SQL Intro, Reciprocal Links & Finding Links with DOM
October 06, 2008 @ 12:09:15

Kevin Waterson has added three new tutorials to his PHPPro.org website recently:

  • Introduction To SQL - The language used in relational databases is SQL. Regardless of the database used, a standard language is used to communicate with them all. This tutorial shows some basic concepts to using SQL.
  • Reciprocal Links - Automating reciprocal links at first glance looks a daunting task. This helper class takes away much of the pain of what can be a mindlessly tedious process and simplifies it into a few easy to use class methods
  • Get Links With DOM - Perhaps the biggest mistake people make when trying to get URLs or link text from a web page is trying to do it using regular expressions. The job can be done with regular expressions, however, there is a high overhead in having preg loop over the entire document many times. The correct way, and the faster, and infinitely cooler ways is to use DOM.

You can find the links to these and many other great tutorials over on the PHPPro.org website's tutorials section.

0 comments voice your opinion now!
tutorial sql intro reciprocal link dom find


SitePoint PHP Blog:
DOM vs. Template
September 25, 2008 @ 11:18:25

In this new post to the SitePoint PHP Blog there's a look at using a small templating engine recently released by Fredrik Holmstrom that takes a different tack on working with template files - it parses them into a DOM structure.

The main difference to traditional template engines (Such as Smarty), is that the template it self doesn't have any imperatives within. In fact, the template doesn't even have to be written to the template engine, to be used - Any markup can be used as a source.

The templating system uses Domlings, bits of HTML to match against and replace with the bound information. A few examples are included - a simple binding, how to switch out a block of HTML, pushing it back in and looping over a block of information to do some search and replace.

0 comments voice your opinion now!
dom template smarty domlings html replace


PHPImpact Blog:
PHP Simple HTML DOM Parser (jQuery Style)
August 08, 2008 @ 12:03:55

On the PHP::Impact blog today Federico points out a few HTML DOM parsers that work similar to jQuery:

Check out a previous tutorial of his for more information on using DOM parsers to scrape information from remote sites.

2 comments voice your opinion now!
dom parser simple html jquery zendomquery phpquery


Developer Tutorials Blog:
Easy Screen Scraping in PHP with the Simple HTML DOM Library
August 06, 2008 @ 08:40:15

On the Developer Tutorials blog today Akash Mehta looks at screen scraping using a simple DOM library to help make it easy.

In PHP, regular expressions tend to get rather messy, DOM calls can be confusing and verbose, and often the string functions just aren't enough. In this tutorial, I'll show you how to use the middle ground - the open source PHP Simple HTML DOM Parser library, which provides jQuery-grade awesomeness for easy screen scraping without messy regular expressions.

In his examples he shows how to grab the contents of a page (google.com), find and replace information in the HTML and perform a query on the data (like finding each of the news stories out of the front page of slashdot.org).

0 comments voice your opinion now!
screen scraping simple html dom library example tutorial


Kae Verans' Blog:
innerHTML in php-dom
July 28, 2008 @ 11:13:16

Kae Verans has written up a handy snippet of code to try to mimic the innerHTML property that Javascript lets you have access to.

DOM does not officially have an innerHTML parameter, but it's incredibly useful. I found a need for something similar when working on some DOM stuff, so had to write a version.

Technically it's an "outerHTML" not inner, but it works about the same. The code and an example of its use is included.

0 comments voice your opinion now!
innrehtml outerhtml dom snippet example


SitePoint PHP Blog:
Mangling XML as Text with PHP DOM
July 24, 2008 @ 09:35:16

In trying to convert over several HTML pages to the DITA XML format, James Edwards came up against a problem involving recursion:

But a problem I came across several times was the sheer complexity of recursive element conversion '" <code> becomes <jsvalue> (or one of a dozen similar elements), <a> becomes <xref> ' and that's all simple enough; but each of these elements might contain the other, or further child elements like <em>, and as we walk through the DOM so the incidence of potential recursion increases, until it gets to the point where my brain explodes.

His solution involves working with both regular expressions and document fragments. He loads the node he wants to work with, its parsed to prepare it and is passed off to do the "text-based mangling" to update it. The result is them pushed back into an XML object (fragment) and this is pushed back into the main document with a replaceChild call.

0 comments voice your opinion now!
dom xml convert dita replacechild fragment node tutorial


MSBWare.com:
XML to Array
April 14, 2008 @ 10:23:11

Michael has posted a simple script today that takes in XML data and spits back out an array on the other side:

The function takes the specified XML data (which must be in valid XML format) and converts into an array. Any attributes in the XML elements are dropped an only the element values are placed in the array.

The code uses a combination of XPath, DOM, and regular expressions to parse the given XML content.

0 comments voice your opinion now!
xml translate array xpath dom regularexpression data element


Greg Szorc's Blog:
Using DTD's and Catalogs for XHTML Validation
April 10, 2008 @ 11:29:48

Greg Szorc shows how, in this entry on his blog, to use DTDs and catalogs to validate your XHTML pages with a little help from PHP.

This [validation from an external site like the W3C validator] approach is a good start, but it is far from ideal because it is based on an honor system of sorts. You often forget to validate each change you make and there is always some corner case that you forget. So, what can be done about it? Well, if you find yourself developing in PHP, you can employ the following solution.

The code he includes pulls in the XHTML content from your page (or the output of the framework's view layer) and pushes it into a DOMDocument that's build with the LIBXML_DTDLOAD and LIBXML_DTDATTR options.

0 comments voice your opinion now!
html validation dom extension document import


DevShed:
Parsing Child Nodes with the DOM XML extension in PHP 5
April 08, 2008 @ 09:47:48

Alejandro Gervasio has finished up his series on DevShed looking at working with the DOM extension in PHP5 with this new article, a look at parsing child nodes.

In this last chapter of the series, I'm going to teach you how to handle the child nodes of an XML document by way of two simple methods, called hasChildNode() and removeChild() respectively. So let's not waste any more time in preliminaries and learn how to use them in a helpful way.

They review some of the concepts mentioned previously before moving ahead to the use of the hasChildNodes and removeChild methods to check for children and get rid of only certain ones.

0 comments voice your opinion now!
dom xml php5 tutorial child node haschildnodes removechild


DevShed:
Accessing Attributes and Cloning Nodes with the DOM XML Extension in PHP 5
April 01, 2008 @ 15:11:43

DevShed continues their series about working with XML in PHP's DOM extension with this new tutorial posted today showing how to get at attributes for tags and cloning nodes from others.

You've probably realized that the DOM XML library can be pretty useful when working with web documents. However, this extension includes some other methods, which can be utilized to parse attributes of a given XML string, as well as to clone nodes.

They show how to use the getAttributes method, hasAttribue method and cloneNode method to work with their XML examples.

0 comments voice your opinion now!
php5 clone node xml tutorial attribute node dom


DevShed:
Handling HTML Strings and Files with the DOM XML Extension in PHP 5
March 26, 2008 @ 08:46:05

On DevShed today, they continue their series looking at working with XML in PHP with the DOM functionality with the fifth part of their series, a look at working with HTML strings and file data.

Understanding how to use the methods and properties provided by this library requires a little effort from you, despite its fairly easy learning curve. [...] 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.

They show how to use loadHTML to pull in the text from an HTML string and use loadHTMLFile to pull it in from an external HTML file. Finally, they show how to write the data and whatever changes you might have made to it, back out to a file with saveHTMLFile.

0 comments voice your opinion now!
tutorial dom extension xml handling html savehtmlfile loadhtml loadhtmlfile


DevShed:
Working with Multiple Document Nodes with the DOM XML Extension in PHP 5
March 19, 2008 @ 07:59:49

DevShed has posted the fourth part of their series looking at working with the DOM functionality of PHP5, this time with a focus on working with multiple document nodes inside of an XML document.

It's time to learn a few other methods included with the DOM XML extension. Based upon this premise, in this fourth tutorial I'm going to show you how to get access to multiple nodes of an XML document, either for internal processing or simply for echoing to the browser.

They show you how to grab the collection of nodes to work with and how to grab data from an XML text file with load() and loadXML().

0 comments voice your opinion now!
dom xml tutorial php5 load set collection object


DevShed:
Inserting Comments and Accessing Nodes with the DOM XML Extension in PHP 5
March 11, 2008 @ 15:40:21

DevShed continues their series looking at using the DOM extension in PHP5 to work with XML in your application. They've already looked at adding attributes and creating CDATA information in a new DOM document. This time they build on that and also include new methods - appending comment nodes and getting at XML nodes by their IDs.

I'm talking about the DOM XML extension, which allows you to handle XML documents by using the DOM API. Thus, if you're interested in learning how to put this extension to work for you quickly, look no further, because you've come to the right place. [...] In this third installment of the series, I'll be teaching you specifically how to append comment nodes to a given XML string and how to extract certain elements via their IDs.

They review the method to add attributes and CDATA to an XML document first. Then they cover the other two new topics - appending comment nodes and grabbing nodes by their ID attribute.

0 comments voice your opinion now!
dom extension php5 node cdata attribute id fetch tutorial


DevShed:
Working with Attributes and CDATA Sections with the DOM XML Extension
March 05, 2008 @ 18:29:00

DevShed has posted a new tutorial today that continues their series looking at XML handling with PHP. This time it's a focus on attributes in a CDATA section with DOM.

Since the DOM XML library comes equipped with many other methods that can be useful for adding custom attributes to the existing nodes of a given XML document, and creating new CDATA sections, among other things.

They start with a review of the DOM functionality to get you reacquainted. From there they move off into the createAttribute function and its use in the creation of CDATA elements in your XML.

0 comments voice your opinion now!
dom extension tutorial createelement cdata section


DevShed:
A Quick Overview of the XML DOM Extension in PHP 5
February 26, 2008 @ 12:26:00

DevShed has started up a new tutorial series today with part one of their overview of the DOM extension that's included with PHP5:

Simply put, the DOM XML extension, as its name suggests, will permit you to work on XML documents by way of the DOM API. [...] In this article series I'll be discussing some of its most relevant methods and properties and accompanying all of these explanations with concise and instructive hands-on examples.

They look at using the DOM to create new documents, modify documents by adding additional nodes and converting over a SimpleXML document to be manipulated.

0 comments voice your opinion now!
dom extension tutorial php5 build modify simplexml


DeveloperTutorials.com:
Scraping Links With PHP
January 14, 2008 @ 08:44:00

The Developer Tutorials site has posted a new article covering the creation of a small application that can help you scrape content from a remote page and pull it into your script.

In this tutorial you will learn how to build a PHP script that scrapes links from any web page.

You'll learn to use cURL, the DOM functions, XPath and a bit of MySQL to get the job done. It's nice to see that they also include a section looking at one of the more touchy aspects of web page scraping - "is it legal?"

0 comments voice your opinion now!
scraping webpage remote curl xpath dom mysql scraping webpage remote curl xpath dom mysql


WebReference.com:
XML-Enabled Applications
September 17, 2007 @ 10:24:00

WebReference.com has an excerpt posted from one of Packt Publishing's latest PHP-related offerings, "PHP Oracle Web Development: Data processing, Security, Caching, XML, Web Services, and Ajax" (by Yuli Vasiliev). This specific chapter talks about XML-enabled applications and how PHP fits into the mix.

Both PHP and Oracle provide comprehensive support for XML and XML-related technologies. Practically, this means you can perform any XML processing either with PHP or inside an Oracle database. [...] This chapter explains how to effectively use XML techniques and technologies available in PHP and Oracle when building XML-enabled PHP/Oracle applications.

They cover the processing of XML in PHP/Oracle apps (including the SAX, DOM and SimpleXML methods), working with XPath and processing the XML in the other half of the two - Oracle's XML processing functionality.

Check out the Packt website for more information on the book.

1 comment voice your opinion now!
xml application oracle process simplexml dom sax xml application oracle process simplexml dom sax


MakeBeta Blog:
Scraping Links With PHP
August 15, 2007 @ 12:08:00

From Justin Laing over at Merchant OS there's a new tutorial on creating a simple link scraper with the help of PHP and the cURL extension.

In this tutorial you will learn how to build a PHP script that scrapes links from any web page. You learn how to use cURL, call PHP DOM functions, use XPath and store the links in MySQL.

You'll have to have PHP5 and the cURL extension enabled on your web server to make it all work, but the code is all there ready for you to cut and paste. The application grabs the page with cURL (including the possibility to fake your user agent), parses through the HTML with the DOM and XPath functionality to grab the links and uses the MySQL methods to store them into your database.

2 comments voice your opinion now!
scrape link curl dom xpath mysql tutorial scrape link curl dom xpath mysql tutorial


Zend Developer Zone:
XML and PHP 5
August 01, 2007 @ 10:13:00

The Zend Developer Zone has a new tutorial posted looking at PHP5 and the new XML tools that it has to offer - as broken up into categories:

Things are a bit different using XML in PHP 5. In a similar scenario, you could use one of the new native extensions, like DOM or SimpleXML, to manipulate the XML data tree. This tree can then be passed directly to and used by the XSL extension without incurring any additional overhead. There is no serialization nor copying involved; ext/xsl is able to work directly with the XML tree it is given, resulting in a significant improvement in use of system resources as compared to coding a similar task in PHP 4. So now that you have an idea why XML support got a face lift, you might like to know about the different tools available to you.
0 comments voice your opinion now!
xml php5 tutorial introduction dom xsl xmlreader xmlwriter simplexml xml php5 tutorial introduction dom xsl xmlreader xmlwriter simplexml


AxisVista Blog:
PHP5 DOM Based Template Engine
July 26, 2007 @ 10:22:00

On the AxisVista blog, there's a new tutorial looking at the creation of a PHP5 DOM-based templating engine that makes it easier for designers to work with a site and not have to know PHP to do so.

At the office today, I had a talk with our designers, so they want a "designer-friendly" template engine. Sounds easy, but it isn't. That is why I decided to write this very short post to help others having such "easy" problems.

First he lays out the requirements for the project, then heads off to Google to see if there's anything similar. He found PRADO but it still lacked some of what he needed. So, deciding on developing his own Templating system, he creates a system that supports:

  • Caching
  • WYSIWYG & Dynamic Tag Handlers
  • States
  • PHP Tags

The code (and results) are included in the post, both in code blocks and for download.

1 comment voice your opinion now!
template engine php5 dom xml designer template engine php5 dom xml designer


Tim Koschuetzki's Blog:
Parsing XML With The DOM Library
June 05, 2007 @ 08:38:00

Tim Koschuetzki has created and posted a new tutorial today that talks about working with XML documents with PHP's DOM Library (the PHP5 version) to create, query and update current documents.

The PHP 4 DOMXML extension has undergone some serious transformation since PHP5 and is a lot easier to use. Unlike SimpleXML, DOM can, at times, be cumbersome and unwieldy. However, it is often a better choice than SimpleXML. Please join me and find out why.

He breaks it out into a few different tasks - saving documents, using XPath queries, updating the contents of an XML file, working with namespaces and playing nice with SimpleXML.

1 comment voice your opinion now!
parse xml dom php5 library simplexml tutorial parse xml dom php5 library simplexml tutorial


Builder.au:
Dynamic XML document construction with the PHP DOM
January 24, 2007 @ 18:32:00

On Builder.au, there's a new tutorial talking about the dynamic construction of an XML document using the DOM functionality already built into most PHP installs out there.

They work through the different steps:

  • Creating the Doctype declaration
  • Adding elements and text nodes
  • Adding attributes
  • Adding CDATA blocks and processing instructions
  • Saving the results
For each on the list, there's code and explanation to help you create the document. By the end, you'll have a document that gives you all the information you'd want to know about someone's pizza order.

0 comments voice your opinion now!
dynamic xml construction dom function tutorial dynamic xml construction dom function tutorial


LoLoCoJr Blog:
Rewriting a (large) PHP application in Rails, part 2
December 20, 2006 @ 10:17:00

The LoLoCoJr site has published part two of the series (part one is here) about converting a PHP application over to Rails.

In my previous post on this topic I described the method we used to convert a legacy MySQL PHP database to a Rails conformant PostgreSQL hosted version. In this article I will tell a bit about how we converted the HTML of the application to Rails layout templates and partials.

It's a quickpost this time showing how to extract the rendered HTML from the page's output, writing out some of the business logic, and a mention of test driven development versus write test after developing methods.

0 comments voice your opinion now!
convert application rails part2 extract dom thml tdd business logic convert application rails part2 extract dom thml tdd business logic


Builder.com:
Dynamic XML document construction with the PHP DOM
December 11, 2006 @ 11:05:00

Builder.com as posted a quick tutorial on working with the DOM functionality in PHP to create a dynamic XML document (Doctype and all).

Over the course of this article, I'll be introducing you to the main functions in this API, showing you how to programmatically generate a complete well-formed XML document from scratch and save it to disk.

They start off with creating the Doctype declaration before actually adding the content into the file (elements and text nodes), adding some attributes to the nodes, putting CDATA blocks inside them, and pushing out the results on the other side to be saved to a local "order.xml" file.

You can also download this article if you'd like to work with it (and its included PHP files) on your own.

0 comments voice your opinion now!
xml dom dynamic document create attribute node doctype cdata xml dom dynamic document create attribute node doctype cdata


Adam Trachtenberg's Blog:
PHP Trivia Contest DOM + Default Namespaces
September 27, 2006 @ 07:25:00

Alright power PHP users out there, Adam Trachtenburg has a little quiz for you to see how much you know about working with the DOM in PHP.

Here's a question based on a recent PHP bug report which shows why DOM is fun. [...] But how do you retrieve it (the namespace URI of the root node) using DOMElement::GetAttributeNS()? What are the two magical input parameters to coax that value out?

The code is simple, but it's an interesting problem - anyone have any answers?

0 comments voice your opinion now!
trivia contest dom handling namespace uri root node trivia contest dom handling namespace uri root node


PHPBuilder.com:
Using XML - Part 6 Validation
July 20, 2006 @ 09:46:37

PHPBuilder.com has posted part six of their "Using XML" series today with a focus on validation techniques using both normal PHP abilities and the XSL functionality in PHP5 with the Schematron language.

This series has so far focused on XML technologies and how they can be utilised using PHP 5. A subject we have not touched upon yet, is XML validation. This article will explore the application independent XML validation standards of DTD's, the XML Schema Language and the XSLT-based Schematron language.

They point back to part one of the series for the XML library they'll use and waste no time getting right into the code. They demonstrate a simple validation first before moving on to the use of DTDs to ensure the correct content. Next up is more work with the XML schemas continuing on to the Schematron functionality (their use and validation).

0 comments voice your opinion now!
xml validation xsl schematron dtd dom tutorial part6 xml validation xsl schematron dtd dom tutorial part6


Christian Stocker's Blog:
Added DOMNodegetNodePath
July 17, 2006 @ 06:37:13

Christian Stocker shares in this new blog post about an update he's made to the DOM functionality in PHP - adding the getNodePath feature.

With this, you can easily get an XPath for any given DOMNode, works also for attributes, text nodes, comments and all other node types. It's basically just a simple wrapper for xmlGetNodePath from libxml2, maybe useful for some other people also.

He gives a code example and notes that more information about XML functionality improvements will be coming from his blog soon.

1 comment voice your opinion now!
dom xml functionality DOMNode getNodePath xmlGetNodePath dom xml functionality DOMNode getNodePath xmlGetNodePath


Chronosight Blog:
Inline AJAX Calendar using PHP
July 12, 2006 @ 14:46:29

On the Chronosight Blog, there's a follow-up post with a look at some enhancements to the original tutorial - Simple Calendar Tutorial.

Almost a year ago I made a tutorial on Simple Calendar Tutorial which trained us to develop a calendar using PHP. Now it times to enhance that tutorial to a whole new level. Let trou in some AJAX code and Javascript Document Object Model (DOM) to create not one, but three type of calendar: Single Calendar, Time Period Selection Calendar, Month-Year Calendar

He steps you through the creation of two files - one to provide a space for the Ajax interface and another for the calendar PHP class. Toss in a little CSS and some explainations along the way and you have all that you need to make a simple, easy to use calendaring system.

0 comments voice your opinion now!
calendar ajax tutorial dom css javascript calendar ajax tutorial dom css javascript


Ben Ramsey's Blog:
Add Children with SimpleXML
May 11, 2006 @ 20:03:57

In this new post on Ben Ramsey's blog today, he shares his experiences with SimpleXML, mentioning specifically some of the undocumented functions that he's noticed.

I was very excited today while glancing through the code in ext/simplexml/simplexml.c to find some, as of yet, undocumented methods in PHP's SimpleXMLElement class. This discovery came after I've spent several hours over the last couple of nights banging my head against the desk to figure out a way to create a class that extends SimpleXMLElement and adds a new method for adding a child, which would have to use DOM in order to work-or so I thought.

Of course, it's wasn't as easy as it seemed, and Ben soon found some of the limitations of the SimpleXML library. Of course, he did manage to find a way to add new children to the document you're working with (something that normally would have required the intervention of the DOM functionality). Check out the post for a code example.

1 comment voice your opinion now!
simplexml add children undocumented feature methods dom xml simplexml add children undocumented feature methods dom xml


PHP.net:
PHP 5.1.4 Released
May 05, 2006 @ 06:29:09

The PHP group has officially released the latest update in the PHP 5.1.x series today - PHP 5.1.4, a bugfix release to take care of the $_POST array handling problem from 5.1.3.

A critical bug with $_POST array handling as well as the FastCGI sapi have been discovered in PHP 5.1.3. A new PHP release 5.1.4 is now available to address these issues. All PHP users are encouraged to upgrade to this release as soon as possible.

Further details about this release can be found in the release announcement and the full list of changes is available in the PHP 5 ChangeLog.

Due to the wide-spread nature of this bug, updating to this latest version would be a very good idea. There are a few other bugs that were fixed in the release as well including issues with the FastCGI sapi, a fix to a possible crash in hightlight_string, cloning of DOM Documents and Noded, and several fixes to the PDO ODBC driver.

You can download this latest update here.

1 comment voice your opinion now!
5.1.4 release official bugfix post fastcgi dom pdo 5.1.4 release official bugfix post fastcgi dom pdo


David Sklar's Blog:
Speed - DOM traversal vs. XPath in PHP 5
February 23, 2006 @ 06:43:03

On his blog today, David Sklar has this new post that compares the speed of two methods of grabbing info from an XML document in PHP5 - DOM traversal versus XPath.

Needing to pick out some bits from a smallish (40 lines) XML document studded with namespaces, I first turned to DomXPath. Worked great, code's concise, XPath expression is simple. But I had the nagging thought that using DOM traversal functions should be faster.

The results from his test? The DOM traversal is about four times faster than using XPath to achieve the same thing.

That 4x speed multiple translates into about a half second to execute for the XPath code and about 0.13 seconds to execute for the DOM code when each is run 10,000 times. Since a typical use of this code will involve it running maybe 10 or 20 times during a request, I'm happy to sacrifice a few microseconds of processor time in exchange for simpler code.

0 comments voice your opinion now!
speed xml parse dom traversal xpath php5 speed xml parse dom traversal xpath php5


PHPBuilder.com:
Using XML - A PHP Developer's Primer
February 07, 2006 @ 07:10:24

PHPBuilder.com has posted a new tutorial targeted at those developers out there wokring to get into the XML functionality that PHP offers. They look to help (in a very general way) introduce you to the fundamentals on what XML is and how to manipulate it with what PHP has to offer.

This series of articles will focus on XML, its applications in modern day web development and how PHP fits into this niche. In this article, we will focus specifically on the tools provided to us by PHP which enable us to manipulate XML data sources.

They cover what XML is, what it looks like, and talk about some of the simple applications that it can bse used for (in PHP or otherwise). They focus on the newer XML features of PHP - DOM, SimpleXML, and XPath. They show some of the PHP code to parse out bits from their sample XML and show how easy it is to port the DOM code over to another language (this time, Javascript). They finish things off with code examples for grabbing the same data in the other technologies - SimpleXML and XPath...

0 comments voice your opinion now!
xml developer primer dom simplexml xpath xml developer primer dom simplexml xpath


IBM developerWorks:
Reading and writing the XML DOM with PHP
December 08, 2005 @ 08:18:57

On the IBM developerWorks page today, there's this new tutorial dealing with reading and writing XML with the DOM functionality in PHP.

Myriad techniques are available for reading and writing XML in PHP. This article presents three methods for reading XML: using the DOM library, using the SAX parser, and using regular expressions. Writing XML using DOM and PHP text templating will also be covered.

They look at what XML is, how to read it into PHP (with examples of DOM, SAX parsers, and regular expression methods), and writing out XML. The DOM functionality that they use for the examples is the newer, PHP5-compatable methods...

0 comments voice your opinion now!
xml reading writing dom php5 xml reading writing dom php5



Community Events





Don't see your event here?
Let us know!


developer list testing release refactor community interview podcast laravel opinion unittest threedevsandamaybe framework code language series install introduction api symfony2

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework