note 68947 added to function.highlight-string

From: Date: Wed, 16 Aug 2006 21:36:30 +0000
Subject: note 68947 added to function.highlight-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-115985@lists.php.net to get a copy of this message
<? // Un ejemplo de como hacer que se vea el numero de lineas // y que no moleste para nada, a la hora de seleccionar el codigo. // agregamos ceros, para que todas las lineas numericas tengan la misma longitud. // 001 // 010 // 100 function agregar0 ($cuantos) { for ($i=0; $i < $cuantos; $i++) { $dev = $dev.'0'; } return $dev; } // parseamos el codigo que nos devuelve la funcion highlight_string function HLS_xhtml ($str) { $str = highlight_string(stripslashes($str), true); $str = str_replace(array('<font ', '</font>'), array('<span ', '</span>'), $str); $str = preg_replace('#color="(.*?)"#', 'style="color: \\1;"', $str); $str = str_replace('<code>', '<code style="white-space: nowrap;">', $str); // obtenemos el numero de lineas $lineas = explode("<br />", $str); ?> <div style="background-color: #0099CC; width: 542px; border: 1px solid #B0B0B0;"> <div style="float: left; color: #FFF; padding: 0 0 0 4px; "> <code style="white-space: nowrap;"> <? // agregamos las lineas en el documento... for ($i=1; $i <= count($lineas); $i++) { $a = strlen(count($lineas)); print agregar0($a - strlen($i)).$i.'<br />'; } ?> </code> </div> <div style="float: right; width: 495px; background-color: #F8F8F8; overflow: auto; overflow-y: hidden; padding: 0 0 0 4px;" id="codigo"><? print $str; ?><br />&nbsp;</div> <div style="clear: both;"><!-- --></div> </div> <? } // ejemplo de uso: $file = file_get_contents(__FILE__); HLS_xhtml($file); #WDEAH ?> ---- Server IP: 200.59.45.3 Probable Submitter: 201.250.24.79 ---- X-Spam-Status: No, hits=4.0 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_50_60,HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.highlight-string.php Edit -- https://master.php.net/note/edit/68947 Del: integrated -- https://master.php.net/note/delete/68947/integrated Del: useless -- https://master.php.net/note/delete/68947/useless Del: bad code -- https://master.php.net/note/delete/68947/bad+code Del: spam -- https://master.php.net/note/delete/68947/spam Del: non-english -- https://master.php.net/note/delete/68947/non-english Del: in docs -- https://master.php.net/note/delete/68947/in+docs Del: other reasons-- https://master.php.net/note/delete/68947 Reject -- https://master.php.net/note/reject/68947 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#115985) next »