cvs: phpweb /include layout.inc
| From: | Gabor Hojtsy | Date: | Sun, 03 Aug 2003 10:17:21 +0000 |
| Subject: | cvs: phpweb /include layout.inc | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-19775@lists.php.net to get a copy of this message | ||
goba Sun Aug 3 06:17:21 2003 EDT
Modified files:
/phpweb/include layout.inc
Log:
Add support for highlighting PHP code with CSS classes used, and
use it on the new zend engine 2 page (code idea from livedocs)
Index: phpweb/include/layout.inc
diff -u phpweb/include/layout.inc:1.171 phpweb/include/layout.inc:1.172
--- phpweb/include/layout.inc:1.171 Mon Jul 21 09:14:33 2003
+++ phpweb/include/layout.inc Sun Aug 3 06:17:21 2003
@@ -1,9 +1,45 @@
<?php
-/* $Id: layout.inc,v 1.171 2003/07/21 13:14:33 goba Exp $ */
+/* $Id: layout.inc,v 1.172 2003/08/03 10:17:21 goba Exp $ */
// Set the static content root differently on php.net
$_SERVER['STATIC_ROOT'] = ($MYSITE == 'http://www.php.net/') ?
'http://static.php.net/www.php.net' :
'';
+
+// Use class names instead of colors
+ini_set('highlight.comment', 'comment');
+ini_set('highlight.default', 'default');
+ini_set('highlight.keyword', 'keyword');
+ini_set('highlight.string', 'string');
+ini_set('highlight.html', 'html');
+
+// Highlight PHP code
+function highlight_php($code, $return = FALSE)
+{
+ // Using OB, as highlight_string() only supports
+ // returning the result from 4.2.0
+ ob_start();
+ highlight_string($code);
+ $highlighted = ob_get_contents();
+ ob_end_clean();
+
+ // Fix output to use CSS classes and wrap well
+ $highlighted = '<div class="phpcode">' . preg_replace(
+ array(
+ '!<br />!',
+ '!<font color="([^"]+)">!',
+ '!</font>!',
+ ),
+ array(
+ "<br />\n",
+ '<span class="\\1">',
+ '</span>',
+ ),
+ $highlighted
+ ) . '</div>';
+
+ if ($return) { return $highlighted; }
+ else { echo $highlighted; }
+}
// Print an image for a sized spacer
function spacer($width = 1, $height = 1, $return = FALSE, $align = FALSE, $extras = FALSE)