Chapter 12. Keeping It Fresh

There's nothing quite like the excitement of discovering a new and interesting website. But this enthusiasm can quickly wane if, after a few visits, the content of the site hasn't changed at all. The primary way of adding new content to a website is by using dynamic, database-driven pages. That's why we've spent so much time discussing MySQL (and will later spend some time on SQLite). Another ideal way of keeping a site current and interesting is by using Rich Site Summary (RSS) feeds. RSS is a file format for web syndication that is widely used by various newsgroups but more commonly encountered in the form of a blog. An RSS file is an Extensible Markup Language (XML) formatted file that can be read using the SimpleXML extension to PHP 5. All you need in order to read an RSS feed is a little knowledge of how an RSS file is structured and an understanding of object-oriented programming (OOP). You'll be surprised at just how easy it is once you've grasped a few basics of XML.

The downside to having a large website with numerous pages is that it can be difficult for casual web surfers to find what they're looking for. For this reason I will also show you how to create a site-specific search. I'll do this using the Google Application Programming Interface (API) and the Simple Object Access Protocol (SOAP) extension to PHP. The Google API will allow us to tap into Google's search capabilities programmatically using the SOAP web service protocol. This protocol uses XML files over HTTP, so some familiarity with XML is required. If you don't know anything about XML, don't worry. You'll learn enough to get you started, and besides, you already know HTML so you're well on your way to understanding XML.

In this chapter you'll also have the opportunity to see how asynchronous JavaScript and XML (AJAX) can work in unison with PHP. We'll use AJAX to insert the Google search results, thus avoiding having to refresh the entire page. In situations where a page reload is overkill, using AJAX can greatly simplify the user interface to a website (though, of course, improper use can do the exact opposite).

The object-oriented (OO) programmer is ideally placed to program using SimpleXML and SOAP because, as you'll see, both extensions are entirely object-oriented. Like it or not, knowledge of OOP is a requirement for taking full advantage of these and many other extensions to PHP.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.91