Google Earth KML Programming Libraries
I've developed a comprehensive KML package for PHP 5 that creates and manages KML XML documents, and 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.
Remember: You can use these classes on your Desktop - they're not just for server web-applications or back-office.
The classes provide each KML element with its own createXXXX() method, has composite buildXXX() methods for building common tag structures (Placemarks, NetworkLinks, etc.), and has convenience methods such as buildIcon(), drawRectangle(), drawCircle(), drawEllipse() and so on. Most importantly it has internal Schema-checking to ensure that only legal parent-child relationships are permitted, so its impossible to inadvertently create a Placemark as the child of a Style, for example.