For this kind of code, you should only use Javascript. Php is a server language, so everything will be HTML to be understood by the browser.
Thus, with a JS script you can do the whole things and take less time to load. And also makes changes AFTER loading. That's why I think ther are nearly no PHP demos...