1
0
mirror of https://github.com/php/web-php.git synced 2026-03-23 23:02:13 +01:00

Add highlighting for code blocks

This commit is contained in:
Roman Pronskiy
2020-11-20 13:11:06 +02:00
committed by Sara Golemon
parent c72e74c178
commit 25b3d36fe1
2 changed files with 19 additions and 2 deletions

View File

@@ -46,6 +46,17 @@ function highlight_php($code, $return = FALSE)
else { echo $highlighted; }
}
// Same as highlight_php() but does not require '<?php' in $code
function highlight_php_trimmed($code, $return = false)
{
$code = "<?php\n" . $code;
$highlighted_code = highlight_php($code, true);
$highlighted_code = preg_replace("/\&lt;\?php(\<br \/\>)+/", '', $highlighted_code, 1);
if ($return) { return $highlighted_code; }
else { echo $highlighted_code; }
}
// Stats pages still need this
function commonHeader($title) { site_header($title); }

View File

@@ -46,14 +46,20 @@ site_header("PHP 8.0.0 Release Announcement", array(
<div class="php8-compare__block example-contents">
<div class="php8-compare__label">PHP 7</div>
<div class="php8-code phpcode">
<pre>htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);</pre>
<?php highlight_php_trimmed(
'htmlspecialchars($string, ENT_COMPAT | ENT_HTML401, \'UTF-8\', false);'
);?>
</div>
</div>
<div class="php8-compare__arrow"></div>
<div class="php8-compare__block example-contents">
<div class="php8-compare__label php8-compare__label_new">PHP 8</div>
<div class="php8-code phpcode">
<pre>htmlspecialchars($string, double_encode: false);</pre>
<?php highlight_php_trimmed(
'htmlspecialchars($string, double_encode: false);'
);?>
</div>
</div>
</div>