This is necessary to obtain a W3C validation (XHTML1.0 Transitionnal)...
phpinfo's output is declared with that DTD :
- "System ID" has the wrong url to validate : "DTD/xhtml1-transitional.dtd" rather than "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
- Some module names contains space and the function's output use the name in anchors as ID and NAME. these attributes can't be validated like that (unique name only).
<?php
ob_start ();
ob_start (); phpinfo (); $info = trim (ob_get_clean ()); $info = preg_replace ('/(id|name)(=["\'][^ "\']+) ([^ "\']*["\'])/i', '$1$2_$3', $info);
$imp = new DOMImplementation ();
$dtd = $imp->createDocumentType (
'html',
'-//W3C//DTD XHTML 1.0 Transitional//EN',
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'
);
$doc = $imp->createDocument (
'http://www.w3.org/1999/xhtml',
'html',
$dtd
);
$doc->encoding = 'utf-8';
$info_doc = new DOMDocument ('1.0', 'utf-8');
@$info_doc->loadXML ($info);
$doc->documentElement->appendChild ( $doc->importNode (
$info_doc->getElementsByTagName ('head')->item (0),
true )
);
$doc->documentElement->appendChild ( $doc->importNode (
$info_doc->getElementsByTagName ('body')->item (0),
true )
);
$style = $doc->getElementsByTagName ('style')->item (0);
$style->appendChild (
$doc->createTextNode (
'/* SOME NEW CSS RULES TO ADD TO THE FUNCTION OUTPUT */'
)
);
$body = $doc->getElementsByTagName ('body')->item (0);
$element = $doc->createElement ('p');
$element->appendChild (
$doc->createTextNode (
'SOME NEW CONTENT TO DISPLAY'
)
);
$body->appendChild ($element);
$head = $doc->getElementsByTagName ('head')->item (0);
$meta = $doc->createElement ('meta');
$meta->setAttribute ('name', 'author');
$meta->setAttribute ('content', 'arimbourg at ariworld dot eu');
$head->appendChild ($meta);
$out = ob_get_clean ();
$pre = $doc->createElement ('div'); $pre->setAttribute ('style', 'white-space: pre;'); $pre->appendChild ($doc->createTextNode ($out));
$body->appendChild ($pre);
$doc->formatOutput = true; $doc->saveXML ();
?>
All that could be done with only RegExp but I prefer the use of DOM for manipulating documents