I am working this afternoon on a top secret project that involves a system to manage pages and pages of HTML content. I won’t go into anymore details, but I do need to work deeply with HTML documents. Anyway, PHPQuery is a cool idea, but after implementing it, I noticed I was getting some odd characters where they were not supposed to be. So, another solution had to be found.
I turned to the Document Object Model (DOM) class built into PHP, which I had not yet used. The documentation sucks, but it is actually a really powerful class. It is, however, lacking one vital function. The ability to get and set the HTML/XML contents of an individual node, that is, the equivalent of the innerHTML property of JavaScript DOM.
I googled for a solution but came up empty. So, I had to invent the solution myself, and after quite some time of tinkering around here’s what I’ve got:
function innerHTML(&$dom, &$node, $html = false) {
## if html parameter not specified, return the current contents of $node
if($html === false) {
$doc = new DOMDocument();
foreach ($node->childNodes as $child)
$doc->appendChild($doc->importNode($child, true));
return $doc->saveHTML();
} else {
## get rid of all current children
foreach ($node->childNodes as $child)
$node->removeChild($child);
## if html is empty, we are done.
if($html == '') return;
## load up $html as DOM fragment, append it to our now-empty $node
$f = $dom->createDocumentFragment();
$f->appendXML($html);
$node->appendChild( $f );
}
}
Not sure if this is the most efficient solution, but from what I’ve seen so far, it works.




Dynamit was honored as one of the “Best Places to Work” in 2010 & 2011 by Columbus Business First newspaper and Interactive Agency of the Year. Times are even better in 2012 and we’re hiring a Web/Graphic Designer for our aggressively growing team.
This is an exciting opportunity to work on cutting edge projects for well-known brands in a dynamic, entrepreneurial and highly creative environment. Please email resumes/cover letters and portfolio information (documents or links to online examples) to Gary Moneysmith via gmoney@dynamit.us.
A web/graphic designer on the Dynamit team will:
Experience is important, but personality is key. Our culture is what drives us, and we’re looking to build our team with someone who both fits and contributes to it.
The position is full time at our office in the Arena District in Columbus, Ohio. We offer a competitive salary and benefits package as well as a fun, high-energy, intellectually-stimulating work environment.
Benefits Include
Don’t sit back. If you want to work in a fast paced work environment with great people who love what they do, apply today.
About Dynamit
Dynamit is a digital agency based in the Arena District in Columbus, Ohio. We work with clients and brands on digital initiatives that include strategy, design, user experience and development. We influence communication and commerce. Client work includes Hilton Worldwide, Charley's Grilled Subs, McGraw-Hill, British Broadcasting Corporation (BBC), E-Z-GO, American Electric Power (AEP), Columbus College of Art & Design and the Ohio State Medical Center (OSUMC) to name but a few.



