CSS & HTML Tips XML Tips and FAQ

HTML DocType Text: World’s Tiniest and Shortest HTML DocType Declaration

Dustin Diaz made an interesting discovery to trigger “standards mode” with just a tiny little declaration instead of the regular lengthy one we see everywhere.

As opposed to “standard mode”, there’s this “quirks mode” in IE that accommodates legacy HTML code of no standards at all – rendering them in many different ways compared with standardized HTML who has a harassing top declaration of document type. For example, common HTML document declarations include:

HTML 4.01 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">

XHTML 1.0 Strict

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">

XHTML 1.0 Transitional

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

XHTML 1.0 Frameset

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "">

For a more detailed collection of HTML doctypes, read here.

However, except for the sake of validation, a declaration usually counts for nothing. The only purpose of leaving one at the top of every web page you create is for the client browser to make the HTML out in standard way rather than in quirks way. Dustin has found a rather convenient short cut for this:

<!doctype html>

It’s much more memorable and correctly triggers the standard mode. We call it the skinny html doctype.

PHP Tips & Tutorials XML Tips and FAQ

How to delete / remove nodes in SimpleXML

The other day I was testing and playing with SimpleXML to process some XML documents when I came to a problem – I realized that I needed to delete a node before dumping the XML object to text. However if you are familiar with SimpleXML, it doesn’t come with a down right way to remove nodes like DOMDocument does.

A few searches on Google neither helped – people were just saying how simple SimpleXML was and it simply could not fulfill a task like this.

You know what I did? Yes, just ‘unset‘ the node.

$str = <<<STR

$xml = simplexml_load_string($str);
unset($xml –> a –> b –> c); // this would remove node c
echo $xml –> asXML(); // xml document string without node c

There you go!