note 100809 added to function.phpinfo

From: Date: Mon, 08 Nov 2010 15:28:57 +0000
Subject: note 100809 added to function.phpinfo
Groups: php.notes 
Request: Send a blank email to php-notes+get-173858@lists.php.net to get a copy of this message
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 (); // Capturing phpinfo (); // phpinfo () $info = trim (ob_get_clean ()); // output // Replace white space in ID and NAME attributes... if exists $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'); /* Parse phpinfo's output * operator @ used to avoid messages about undefined entities * or use loadHTML instead */ @$info_doc->loadXML ($info); $doc->documentElement->appendChild ( // Adding HEAD element to HTML $doc->importNode ( $info_doc->getElementsByTagName ('head')->item (0), true // With all the subtree ) ); $doc->documentElement->appendChild ( // Adding BODY element to HTML $doc->importNode ( $info_doc->getElementsByTagName ('body')->item (0), true // With all the subtree ) ); // Now you get a clean output and you are able to validate... /* echo ($doc->saveXML ()); // OR echo ($doc->saveHTML ()); */ // By that way it's easy to add some style declaration : $style = $doc->getElementsByTagName ('style')->item (0); $style->appendChild ( $doc->createTextNode ( '/* SOME NEW CSS RULES TO ADD TO THE FUNCTION OUTPUT */' ) ); // to add some more informations to display : $body = $doc->getElementsByTagName ('body')->item (0); $element = $doc->createElement ('p'); $element->appendChild ( $doc->createTextNode ( 'SOME NEW CONTENT TO DISPLAY' ) ); $body->appendChild ($element); // to add a new header : $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); // As you wish, take the rest of the output and add it for debugging $out = ob_get_clean (); $pre = $doc->createElement ('div'); // or pre $pre->setAttribute ('style', 'white-space: pre;'); // for a div element, useless with pre $pre->appendChild ($doc->createTextNode ($out)); $body->appendChild ($pre); $doc->formatOutput = true; // For a nice indentation $doc->saveXML (); ?> All that could be done with only RegExp but I prefer the use of DOM for manipulating documents ---- Server IP: 217.71.118.166 Probable Submitter: 109.128.240.90 ---- Manual Page -- http://www.php.net/manual/en/function.phpinfo.php Edit -- https://master.php.net/note/edit/100809 Del: integrated -- https://master.php.net/note/delete/100809/integrated Del: useless -- https://master.php.net/note/delete/100809/useless Del: bad code -- https://master.php.net/note/delete/100809/bad+code Del: spam -- https://master.php.net/note/delete/100809/spam Del: non-english -- https://master.php.net/note/delete/100809/non-english Del: in docs -- https://master.php.net/note/delete/100809/in+docs Del: other reasons-- https://master.php.net/note/delete/100809 Reject -- https://master.php.net/note/reject/100809 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173858) next »