några sidor på nätet om PHP programmering

Sök efter  
Börja här Uppgifter Testa dig själv Tips Sidokarta mm. Länkar Sök

links.php compat.php settings.php source.php main.txt Typisk sida

5.2.4 source.php

Används för att visa källkod

<?php

include_once( dirname(__FILE__) . "/compat.php");
$fn = 1;
function
myShow_Source( $fileName , $dangerous=false, $showres=true )
{

    
$fno = figno();
    if(
$fileName == "./samples/_server.php" )
        
$fileName = "./samples/_server.txt";

    echo
"<div class=\"source\">";
    if (
$fileName == "phpinfo.php" )
    {
        
highlight_string("<?php \nphpinfo();\n?>");
    }
    else
    {
        
$a = file ( $fileName ) or die( "Kunde inte öppna filen<br />" );
        
$a = implode($a, "");
        
ob_start();
        
highlight_string($a);
        
$a = ob_get_contents ();
        
ob_end_clean();
        if (
$fileName != "./inc/source.php" )
        {
            
$a = str_replace("/*NY*/", "<b>", $a);
            
$a = str_replace("/*/NY*/", "</b>", $a);
            
$a = str_replace("/*BORT", "<span style=\"text-decoration:
                        line-through; \">"
, $a);
            
$a = str_replace("BORT*/", "</span>", $a);

            
$a = str_replace("&lt;!--NY--&gt;", "<b>", $a);
            
$a = str_replace("&lt;!--/NY--&gt;", "</b>", $a);
        }

        echo
$a;
        
# show_source( $fileName ) or die( "Kunde inte öppna filen<br />" );
    
}
    echo
"</div>";
    echo
"<div align=\"right\"><font size=\"1\">Listning " .
        
$fno . " - " .
        
str_replace( "./", "" , $fileName ) ;
    if (!
$showres)
    {
        if (
substr(basename($fileName),0,3) != "php" &&
                
$fileName != "./samples/_server.txt"  )
        {
            if (
strpos( $fileName, "inc/") == 0 )
                echo
"<br><a href=\"./samples/visa.php?vad=" .
                    
$fileName .
                    
"\" target=\"_blank\">[Visa i separat f&ouml;nster]</a>";
        }
#        else
#            echo "<br /><b>Vill inte visa resultatet</b>";
    
}
    echo
"</font></div><br clear=\"all\" />";
    if (
$showres )
    {
        echo
"<div class=\"res\">";
        if (
$dangerous )
        {
            
$realFile = "http://" . _ServerData( "SERVER_NAME" ) .
                        
dirname( _ServerData( "SCRIPT_NAME" ) ) .
                        
"/".
                        
$fileName ;
                        
#http://localhost/enges.org/phpkurs/./samples/s115.php
            
$realFile = str_replace("/./", "/", $realFile );
            
readfile ($realFile) or die("Kunde inte öppna " . $realFile);
        }
        else
        {
            include(
$fileName  );
        }
        echo
"</div>";
        echo
"<div align=\"right\"><font size=\"1\">Resultat av listning " .
                
$fno . "</font></div><br clear=\"all\" />";

    }
}

function
figNo()
{
    global
$fn;
    global
$navList;

    if(
$navList->currLev == 1)
    {
        return
$navList->lastCurrInd1Count .
                        
"." .
                        
$fn++;
    }
    elseif(
$navList->currLev == 2 )
    {
        return
$navList->lastCurrInd1Count .
                        
"." .
                        (
$navList->lastCurrInd2Count) .
                        
"." .
                        
$fn++;
    }
    elseif(
$navList->currLev == 3 )
    {
        return
$navList->lastCurrInd1Count .
                        
"." .
                        (
$navList->lastCurrInd2Count) .
                        
"." .
                        (
$navList->lastCurrInd3Count) .
                        
"." .
                        
$fn++;
    }

}
?>
Listning 5.2.4.1 - inc/source.php

   Sidokarta mm.Källkodersource.php