PDA

View Full Version : نمایش سورس صفحه



majoran
شنبه 01 آبان 1389, 09:15 صبح
سلام
آیا تابعی وجود داره که این امکان رو بده تا من سور صفحه خودم رو داشته باشم مثلا من در صفحه خودم بیام دستور زیر رو بنویسم

<?php echo "salam"; ?>
نتیجه صفحه اولا salam باشه یعنی نتیجه دستورات php و بعد از اونم

<?php echo "salam"; ?>
اینو نمایش بده

Reza1607
شنبه 01 آبان 1389, 11:01 صبح
بله این امکانش هست شما با کد زیر می تونید سورس فایلتون رو ببینین


$html_code = highlight_file($filename, TRUE);

که به جای $filename مسیر فایلتون رو نمایش می دین

Reza1607
شنبه 01 آبان 1389, 11:04 صبح
اینم نمونه اش ( شماره هم می زاره)


function get_sourcecode($filename, $first_line_num=1, $num_color="#999") {
// Get highlighted code
//echo "Path File : $filename";
$html_code = highlight_file($filename, TRUE);
// Bookmark #1:
// Remove the first "<code>" tag from "$html_code" (if any)
if (substr($html_code, 0, 6) == "<code>") {
$html_code = substr($html_code, 6, strlen($html_code));
}
// Replacement-map to replace deprecated "<font>" tag with "<span>"
$xhtml_convmap = array(
'<font' => '<span',
'</font>' => '</span>',
'color="' => 'style="color:'
);
// Replace "<font>" tags with "<span>" tags, to generate a valid XHTML code
$html_code = strtr($html_code, $xhtml_convmap);
### Okay, Now we have a valid XHTML code
### Let's add the line numbers...
$arr_html_code = explode("<br />", $html_code);
$total_lines = count($arr_html_code);
$retval = "";
$line_counter = 0;
$last_line_num = $first_line_num + $total_lines;
foreach ($arr_html_code as $html_line) {
// Calculate number of current line
$current_line = $first_line_num + $line_counter;
// Append new line to "$retval"
$retval .=str_repeat("&nbsp;", strlen($last_line_num) - strlen($current_line) ) ."<span style=\"color:{$num_color}\">";
$retval.=$current_line.". ";
$retval.="</span>" .$html_line ."<br />";
$line_counter++;
} // end: foreach
$retval = "<code>" . $retval; // Why? remember Bookmark #1, that I removed the tag "<code>"
return $retval;
} // end: get_sourcecode