Commit: 25b3d36fe166053be8fd39cebccef5732d7f9f8a Author: Roman Pronskiy <[email protected]> Fri, 20 Nov 2020 13:11:06 +0200 Committer: Sara Golemon <[email protected]> Wed, 25 Nov 2020 20:28:13 +0000 Parents: c72e74c178619829440e6ad48bfb406783776fde Branches: master
Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=25b3d36fe166053be8fd39cebccef5732d7f9f8a Log: Add highlighting for code blocks Changed paths: M include/layout.inc M releases/8_0_x.php Diff: diff --git a/include/layout.inc b/include/layout.inc index e994ebe91..9f2509b05 100644 --- a/include/layout.inc +++ b/include/layout.inc @@ -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("/\<\?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); } diff --git a/releases/8_0_x.php b/releases/8_0_x.php index 8d8aff699..c22dc257f 100644 --- a/releases/8_0_x.php +++ b/releases/8_0_x.php @@ -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> -- PHP Webmaster List Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
