I've recently created a comprehensive KML class for PHP that creates and manages KML XML documents, can output KML plain text or KMZ gzipped data. It supports sending data directly to the Google Earth client, or providing it for download from a web page as KML or KMZ.
Many people seem more interested in the associated KML Documentation, Examples, and TutorialThe class provides each KML element with its own createXXXX() method, has composite buildXXX() methods for making common tag structures (Placemarks, NetworkLinks, etc.).
Most importantly it has
internal consistency checking matrices to ensure that only legal parent-child relationships are permitted, so its impossible to inadvertently create a Placemark as the child of a Simple tag, for example.
A KML XML Schema is evolving from it, auto-generated (again by the class) as it gets more sophisticated
This means its hard to send the Google Earth client a KML file that will cause an error on loading, saving valuable time and enhancing user experience.
As a bonus, the internal modelling of the KML tag relationships means that in two lines of code the entire relationship can be displayed - *very* useful for developing valid KML quickly and making sure you make use of all the features.
KML Schema, DTD, and PHP classes TJ