我想从文件中包含一个代码示例而不执行它。
但我不知道为什么函数如fread()
或file_get_contents()
剪切包含文件的前 9 行。
包含而不执行代码(我尝试过的多种方法之一):
<?php
// get contents of a file into a string
$filename = "index_GD.php";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
echo "<pre><codesample>".$contents."</codesample></pre>";
fclose($handle);
?>
包含文件的前 11 行:
<?php
// Set the content-type
header('Content-Type: image/png');
function imagegradientellipse($image, $cx, $cy, $w, $h, $ic, $oc){
$w = abs($w);
$h = abs($h);
$oc = array(0xFF & ($oc >> 0x10), 0xFF & ($oc >> 0x8), 0xFF & $oc);
$ic = array(0xFF & ($ic >> 0x10), 0xFF & ($ic >> 0x8), 0xFF & $ic);
$c0 = ($oc[0] - $ic[0]) / $w;
输出(前 11 行):
> 0x10), 0xFF & ($oc >> 0x8), 0xFF & $oc);
$ic = array(0xFF & ($ic >> 0x10), 0xFF & ($ic >> 0x8), 0xFF & $ic);
$c0 = ($oc[0] - $ic[0]) / $w;
$c1 = ($oc[1] - $ic[1]) / $w;
$c2 = ($oc[2] - $ic[2]) / $w;
$i = 0;
$j = 0;
$is = ($w<$h)?($w/$h):1;
$js = ($h<$w)?($h/$w):1;
while(1){