Índice

XML (Extensible Markup Language)

Well Formed

Valid

Parsing XML

XML Extension

DOM

SimpleXML

SimpleXml

Namespaces

DOM Document

$dom = new DomDocument();
$dom->load("library.xml"); or $dom->loadXML($xml); // $xml is a string$dom->loadHTMLFile("library.html"); or $dom->loadHTML($html);
$dom->save(); // (to a file)
$dom->saveXML(); // (to a string)
$dom->saveHTML(); // (also to a string, but saves an HTML document instead of an XML file)
$dom->saveHTMLFile(); // (to a file in HTML format).
$xpath = new DomXpath($dom); // use XPath
$result = $xpath->query("//lib:title/text()"); // to execute XPath query
foreach($result as $book) {echo $book->data;} // $result->length gives the no. of items

DomNode

Removing

DOM and SimpleXML

Pre-defined Constants

XPath

XPath Searches

Web Services

REST

SOAP

PHP SOAP Client

The functions (generally) take a WSDL file as input, and create an object that mimics the services of the web service:

$client = new SoapClient("http://soap.amazon.com/schemas2/AmazonWebServices.wsdl");
API call
$result = $client->KeywordSearchRequest($params);
Debugging
$client = new SoapClient('http://api.google.com/GoogleSearch.wsdl', array('trace' => 1));
$client->__getLastRequestHeaders();
$client->__getLastRequest();

PHP SOAP Server

start with a class that contains the methods you wish to make available to the public through aWeb service and use it as the basis for a SoapServer instance
NOT generate WSDL files automatically (unlike NuSOAP, Zend Studio)
may operate on the non-WSDL mode

$options = array('uri' => 'http://example.org/soap/server/');
$server = new SoapServer(NULL, $options);
$server->setClass('MySoapServer');
$server->handle();

DateTime

Examples:

date.timezone = “Asia/Hong_Kong”; // in php.ini OR
date_default_timezone_set("Asia/Hong_Kong");

$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
$now = time(); echo 'Today is '.date('d/m/Y'); // Today is 04/06/2013

$objDateTime = new DateTime('2000-01-01', new DateTimeZone('Asia/Hong_Kong'));
$objDateTime->modify('+1 day');
echo $objDateTime->format('c');

Date formats

and the following predefined constants can also be used (available since PHP 5.1.0):

JSON & AJAX

{
   "employees": [
      { "firstName":"John" , "lastName":"Doe" },
      { "firstName":"Peter" , "lastName":"Jones" }
   ]
}