note 127170 added to function.highlight-file

From: Date: Fri, 10 Jun 2022 17:37:19 +0000
Subject: note 127170 added to function.highlight-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-218581@lists.php.net to get a copy of this message
Updating the example https://www.php.net/manual/pt_BR/function.highlight-file.php#92697 <?php function highlightContentOfFile( string $file, ?bool $showLineNumbers = true, ?bool $insertFinalNewLine = true, string $lineHeight = '1.1rem' ) { $showLineNumbers = $showLineNumbers ?? true; $insertFinalNewLine = $insertFinalNewLine ?? true; $endLine = (int) $insertFinalNewLine; $lineCount = count(file($file)) + $endLine; $lines = array_reduce(range(1, $lineCount), fn ($keep, $item) => $keep .= "<li>{$item}</li>\n", ''); $content = highlight_file($file, true); $randomInt = rand(); $style = " <style> table.table-code-{$randomInt} tr td.num-{$randomInt} { float: left; color: gray; font-size: 13px; font-family: monospace; text-align: right; margin-right: 6pt; padding-right: 0; border-right: 1px solid gray; line-height: {$lineHeight}; background: #80808026; font-weight: bold; } body {margin: 0px; margin-left: 5px;} table.table-code-{$randomInt} tr td {vertical-align: top;} table.table-code-{$randomInt} tr td code { white-space: nowrap; line-height: {$lineHeight}; } table.table-code-{$randomInt} tr td.num-{$randomInt} ul { margin: 0; padding: 0.1rem 0.5rem 0.1rem 0.1rem; list-style: none; min-width: 2.5rem; } </style> "; $linesContent = !$showLineNumbers ? '' : <<<"HTML" {$style} <td class="num-{$randomInt}"> <ul>$lines</ul> </td> HTML; return <<<"HTML" <table class="table-code-{$randomInt}"> <tr> {$linesContent} <td>$content</td> </tr> </table> HTML; } echo highlightContentOfFile(__FILE__, true, true, '20px'); ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.12.131 (proxied: 187.32.131.210) ---- Manual Page -- https://php.net/manual/en/function.highlight-file.php Edit -- https://main.php.net/note/edit/127170 Del: integrated -- https://main.php.net/note/delete/127170/integrated Del: useless -- https://main.php.net/note/delete/127170/useless Del: bad code -- https://main.php.net/note/delete/127170/bad+code Del: spam -- https://main.php.net/note/delete/127170/spam Del: non-english -- https://main.php.net/note/delete/127170/non-english Del: in docs -- https://main.php.net/note/delete/127170/in+docs Del: other reasons-- https://main.php.net/note/delete/127170 Reject -- https://main.php.net/note/reject/127170 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#218581) next »