rbprogrammer
November 23rd, 2008, 12:43 AM
Ok, so I have this code in a PHP script on my server:
$body = $_GET['body'];
if( $body == "source" )
{
println("<html>");
println("<head>");
println("<title>Website Source Code</title>");
println("</head>");
println("<body>");
println("<pre>");
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
$lines = file($pfile);
if( $lines != false )
{
$numbers = "";
$codelines = "";
foreach ($lines as $line_num => $line)
{
$numbers = $numbers . ($line_num+1) . " : <br/>\n";
$codelines = $codelines . htmlspecialchars($line) . "<br/>\n";
}
println("<table>");
println(" <tr>");
println(" <td>" . $numbers . "</td>");
println(" <td>" . $codelines . "</td>");
println(" </tr>");
println("</table");
}
println("</pre>");
println("</body>");
println("</html>");
exit;
}
Basically, when the variable body equals "source", I want to display the source code of that PHP script. But, for some reason, whitespace is not being displayed in the browser. Meaning all the code is at one level with no indentations. Looking at the source code, there are the spaces there. But for some reason, firefox is not showing it. What am I doing wrong? I though the pre tage was supposed to preserve white space and display it....
$body = $_GET['body'];
if( $body == "source" )
{
println("<html>");
println("<head>");
println("<title>Website Source Code</title>");
println("</head>");
println("<body>");
println("<pre>");
$file = $_SERVER["SCRIPT_NAME"];
$break = Explode('/', $file);
$pfile = $break[count($break) - 1];
$lines = file($pfile);
if( $lines != false )
{
$numbers = "";
$codelines = "";
foreach ($lines as $line_num => $line)
{
$numbers = $numbers . ($line_num+1) . " : <br/>\n";
$codelines = $codelines . htmlspecialchars($line) . "<br/>\n";
}
println("<table>");
println(" <tr>");
println(" <td>" . $numbers . "</td>");
println(" <td>" . $codelines . "</td>");
println(" </tr>");
println("</table");
}
println("</pre>");
println("</body>");
println("</html>");
exit;
}
Basically, when the variable body equals "source", I want to display the source code of that PHP script. But, for some reason, whitespace is not being displayed in the browser. Meaning all the code is at one level with no indentations. Looking at the source code, there are the spaces there. But for some reason, firefox is not showing it. What am I doing wrong? I though the pre tage was supposed to preserve white space and display it....