note 43805 added to function.show-source
| From: | chuayw2000 at hotmail dot com | Date: | Sun, 04 Jul 2004 15:06:54 +0000 |
| Subject: | note 43805 added to function.show-source | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72523@lists.php.net to get a copy of this message | ||
The following code will highlight the code with line numbers (though with no formatting), will add
links to referenced files, and will link functions and control structures to the PHP Manual.
<?php
function convert_link($text, $base_dir = ""){
global $source_link_matches;
$base = basename($base_dir);
$base_dir = str_replace($base,"",$base_dir);
//echo $base_dir."<br>";
//Parse the text
$listed = array();
if (preg_match_all("/[A-z0-9\-_\.~ ]{1,1}[A-z0-9\-_\.~\/
]+\.[A-z0-9]+/",$text,$matches,PREG_SET_ORDER)){
$source_link_matches .= "\r\n".print_r($matches,true);
//Replace them!
for ($i = 0; $i <= count($matches) - 1; $i++){
//Check whether it has been listed
if (in_array($matches[$i][0],$listed)){
continue;
}
//Check it exists first
if (file_exists($base_dir.$matches[$i][0])){
$text = str_replace($matches[$i][0],'<a
href="source.php?p='.$base_dir.$matches[$i][0].'"
class="link">'.$matches[$i][0].'</a>',$text);
//Add them to an array containing the already highlighted address.
$listed[] = $matches[$i][0];
}
//Check if it exists from here
elseif (file_exists($matches[$i][0])){
$text = str_replace($matches[$i][0],'<a
href="source.php?p='.$matches[$i][0].'"
class="link">'.$matches[$i][0].'</a>',$text);
//Add them to an array containing the already highlighted address.
$listed[] = $matches[$i][0];
}
}
}
return $text;
}
$p = "rss.php";
$source = show_source($p,true);
$database = explode("<br />",$source);
echo "<table
border='1'><tr><td>Line</td><td>Code</td></tr>";
for ($i = 0; $i <= count($database)-1; $i ++){
$lineno = $i+1;
echo "<tr><td valign=\"top\"><a
name=\"line$lineno\">$lineno</a></td><td><code>".
preg_replace(
'{([\w]+)(\s*</font><font\s+color="'
.ini_get('highlight.keyword').'">|)(\s*\()}',
'<a title="PHP Manual - $1()"'
.' href="http://www.php.net/$1">$1</a>$2$3'
,
convert_link(strip_tags($database[$i]),$p))."</code></td></tr>";
}
echo
"<tr><td>Line</td><td>Code</td></tr></table>";
?>
You can see an example @ www.chuayw.aznpride.net/source.php?p=index.php
----
Manual Page -- http://www.php.net/manual/en/function.show-source.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43805
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43805&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43805&report=yes
Search -- http://master.php.net/manage/user-notes.php