* ``` * * @internal */ final class PhpInfoViewHelper extends AbstractViewHelper { /** * @var bool */ protected $escapeOutput = false; /** * @var bool */ protected $escapeChildren = false; public function render(): string { return self::removeAllHtmlOutsideBody(self::changeHtmlToHtml5(self::getPhpInfo())); } /** * Get information about PHP's configuration as HTML string */ private static function getPhpInfo(): string { ob_start(); phpinfo(); return (string)ob_get_clean(); } /** * Remove all HTML outside the body tag from HTML string. */ private static function removeAllHtmlOutsideBody(string $html): string { // Delete anything outside the body tag and the body tag itself $html = (string)preg_replace('/^.*?/is', '', $html); return (string)preg_replace('/<\/body>.*?$/is', '', $html); } /** * Change HTML markup to HTML5. * * @param string $html HTML markup to be cleaned */ private static function changeHtmlToHtml5(string $html): string { // Delete obsolete attributes $html = (string)preg_replace('#\s(cellpadding|border|width)="[^"]+"#', '', $html); // Replace font tag with span return str_replace([''], [''], $html); } }