O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

PHP Web 2.0 Mashup Projects: Create practical mashups in PHP, grabbing and mixing data from Google Maps, Flickr, Amazon, YouTube, MSN Search, Yahoo!, Last.fm, and 411Sync.com

Book Description

This practical tutorial has detailed, carefully explained case studies using PHP to build new, effective mashup applications, which combine data from multiple external online sources into an integrated Web 2.0 experience. If you are confident with PHP programming and interested in mashing things up, this book is for you! All you need to know about formats, protocols, web services, and web APIs is covered as you learn to write PHP code to remotely consume services like Google Maps, Flickr, Amazon, YouTube, MSN Search, Yahoo!, Last.fm, the Internet UPC Database, and even the California Highway Patrol Traffic data! The 5 real-world PHP projects each start with an overview of technologies and protocols needed and then dive into the tools used and details of creating the project, and you can download each project's source code. You will learn how these technologies work with each other and how to use this information, together with your imagination, to build your own cutting-edge websites.

Table of Contents

  1. PHP Web 2.0 Mashup Projects
  2. Credits
  3. About the Author
  4. About the Reviewer
  5. Preface
    1. What This Book Covers
    2. What You Need for This Book
    3. Conventions
      1. Reader Feedback
    4. Customer Support
      1. Downloading the Example Code for the Book
      2. Errata
      3. Questions
  6. 1. Introduction to Mashups
    1. Web 2.0 and Mashups
      1. Importance of Data
      2. User Communities
    2. How We Will Create Mashups
    3. More Mashups
  7. 2. Buy it on Amazon
    1. XML-RPC
      1. XML-RPC Structure
        1. XML-RPC Request
          1. XML-RPC Data Types
          2. Scalar Values
          3. String
          4. Integer
          5. Double
          6. Boolean
          7. Date/Time
          8. Base64-Encoded Binary
        2. Arrays
        3. Struct
      2. XML-RPC Response
    2. Working with XML-RPC in PHP
      1. Making an XML-RPC Request
        1. Serializing Data with XML-RPC Encode Request
          1. Creating a Single Parameter XML-RPC Request
          2. Double Data Type
          3. Date/Time and Base64 Data Types
          4. Creating a Multiple Parameter XML-RPC Request
          5. Passing Arrays in XML-RPC Requests
          6. Passing Struct in XML-RPC Requests
        2. Calling XML-RPC Using Sockets
    3. Processing an XML-RPC Response
      1. Creating an XML-RPC Parser Class
        1. Testing Our XML-RPC Parser Class
      2. Using PEAR to Handle XML-RPC
    4. REST
    5. Working with REST in PHP
      1. Making a REST Request
        1. A GET and POST Refresher
        2. Using Sockets to Initiate a REST Request
        3. Creating GET and POST Request Functions
        4. Making a REST Parser Class
        5. Testing Our REST Parser Class
      2. Processing a REST Response
        1. Basic Walkthrough with PHP and SAX
          1. Using the PHP’s XML Functions
          2. Setting up the Callback Functions
          3. Seeing the Callbacks in Action
        2. Creating a SAX Parser Class
          1. Examining the Classes
          2. Using and Testing the Class
    6. Internet UPC Database API
    7. Amazon API
      1. A Tour of ECS
      2. Anatomy of an ECS REST Request
        1. Location of Service
    8. Mashing Up
      1. Product Lookups
        1. Handling Amazon’s XML Responses
          1. An ECS Lookup Response
          2. Your Own Amazon Cart
    9. Summary
  8. 3. Make Your Own Search Engine
    1. SOAP
      1. Web Services Descriptor Language (WSDL) With XML Schema Data (XSD)
        1. Basic WSDL Structure
        2. definitions Element
        3. types Element
          1. Simple Type
          2. Complex Type
          3. Arrays
        4. message Element
          1. RPC Binding
          2. Document Binding
        5. portType Element
        6. binding Element
        7. service Element
      2. The SOAP Message
        1. Envelope
        2. Header
        3. Body
          1. RPC Binding
          2. Document Binding
        4. Fault
    2. PHP’s SoapClient
      1. Creating Parameters
      2. Instantiate the SoapClient
        1. Instantiating in WSDL Mode
        2. Instantiating in Non-WSDL Mode
      3. Making the Call and Using SoapClient Methods
        1. Calling SOAP Operations in WSDL Mode
        2. Calling SOAP Operations in Non-WSDL Mode
      4. Handling the SOAP Response
        1. Handling SOAP Errors with SoapFault
        2. Handling Successful Results
    3. Microsoft Live Search Web Service
      1. Using Search
    4. Yahoo! Search Web Service
      1. Using Web Search
    5. Mashing Up
    6. Summary
  9. 4. Your Own Video Jukebox
    1. XSPF
    2. RSS
    3. YouTube Overview
      1. YouTube Developer API
    4. Last.fm Overview
      1. Audioscrobbler Web Services
    5. Parsing With PEAR
      1. Package Installation and Usage
      2. File_XSPF
      3. Services_YouTube
      4. XML_RSS
    6. Mashing Up
      1. Mashup Architecture
      2. Main Page
      3. Navigation Page
      4. Content Page
      5. Using the Mashup
    7. Summary
  10. 5. Traffic Incidents via SMS
    1. Screen Scraping the PHP Way
      1. Parsing with DOM Functions
        1. Basic Element and Attribute Parsing
        2. Testing the Schema
        3. More About PHP’s Implementation of the DOM
    2. 411Sync.com API
      1. Creating Your Mobile Search Keyword
        1. Name Your Keyword
        2. Format the Users will Use when They Use Your Search
        3. HTTP Location of the XML Data
    3. California Highway Patrol Incident Page
    4. Mashing Up
      1. The Incident Class
      2. The DOM Parser Class
      3. The CHP DOM Parser Class
      4. Creating the Feed Page
      5. Testing and Deploying
    5. Summary
  11. 6. London Tube Photos
    1. Preliminary Planning
    2. Finding Tube Information
    3. Integrating Google Maps and Flickr Services
    4. Application Sequence
    5. Resource Description Framework (RDF)
    6. SPARQL
      1. Analyzing the Query Subject
      2. Anatomy of a SPARQL Query
      3. Writing SPARQL WHERE Clauses
        1. Basic Principles
        2. A Simple Query
        3. Querying for Types
        4. Ordering, Limiting, and Offsetting
        5. UNION and DISTINCT
      4. More SPARQL Features
    7. RDF API for PHP (RAP)
    8. XMLHttpRequest Object
      1. XMLHttpRequest Object Overview
      2. Using the Object
        1. Creating the Object
        2. Making the HTTP Request
        3. Creating and Using the Callback
    9. JavaScript Object Notation (JSON)
      1. JavaScript Objects Review
      2. JSON Structure
      3. Accessing JSON Properties
      4. Serializing the JSON Response
    10. Google Maps API
      1. Creating a Map
      2. Geocoding
      3. Markers
      4. Events
      5. InfoWindow Box
    11. Flickr Services API
      1. Executing a Search
      2. Interpreting Service Results
      3. Retrieving a Photo or a Photo’s Page
    12. Mashing Up
      1. Building and Populating the Database
        1. Examining the File
        2. Creating Our Database Schema
        3. Building SPARQL Queries
        4. Stations Query
        5. Lines Query
        6. Lines to Stations Query
        7. Database Population Script
      2. The TubeSource Database Interface Class
      3. The Main User Interface
      4. Using Flickr Services with AJAX
        1. Creating an XMLHttpRequest Proxy
        2. Modifying the Main JavaScript
        3. Making the XMLHttpRequest
        4. Race Conditions
        5. Parsing the AJAX Response
    13. Summary