网站上的空白问题,很难理解啊
网站上有一块是称为模块的调用方式,首页上就是调用不同的模块来完成的,不过发现凡是调用模块的地方,居然输出内容上访都有一个空白,但是输出的代码没有问题。
已经脱离出3个文件,一个文件为主文件,另外两个为类似的执行文件,当主文件包含执行文件1的时候没有空白,包含2的时候就有空白,两个执行文件唯一的差别是文件1没有html缓存,文件2有。
主文件:
<?php
$mosConfig_absolute_path="E:/web/skytest/bugtest";
require_once("mod_test.php");
?>
执行文件1(部分):
<style type="text/css">
body{
padding: 0px ;
margin: 0px ;
}
.waihui{
border: 1px solid red ;
}
</style>
<?php
//获取
function getWaihui(){
$file="http://www.cmbchina.com/cmb2005web/cmbaspxbin/rate/RealTimeFxRate.aspx";
$max=10000000;
$rand = rand(0,$max)/$max;
$file = sprintf($file,$rand);
$content = iconv("gb2312","utf-8//IGNORE",file_get_contents($file));
preg_match('/\\d{4}年\\d{2}月\\d{2}日/si',$content,$date);
$results['date']=$date[0];
preg_match('/ExrateDataGrid[^>]*?>(.*?)<\\/table>/si',$content,$match);
$content=$match[1];
$content = preg_replace('/(<[^\\/][^>]*?>|<\/font>|\s*)/si','',$content);
$content = explode('</tr>',$content);
$content = array_filter($content,'filterArray');
$name = array("hkd"=>"香港ドル","aud"=>"オーストラリアドル","usd"=>"米ドル","eur"=>"ユーロ","cad"=>"カナダドル","gbp"=>"英ポンド","jpy"=>"日本円","donotwant"=>"シンガポールドル","chf"=>"スイスフラン");
for($i=1;$i<count($content);$i++){
$tmp = explode('</td>',trim($content[$i]));
$result[] = trim($tmp[3])/100;
}
$i=0;
foreach($name as $eng=>$name){
if($eng == 'donotwant'){
$i++;
continue;
}
$results[$eng] = $result[$i];
$i++;
}
return $results;
}
function format($result){
$name = array("hkd"=>"香港ドル","aud"=>"オーストラリアドル","usd"=>"米ドル","eur"=>"ユーロ","cad"=>"カナダドル","gbp"=>"英ポンド","jpy"=>"日本円","donotwant"=>"シンガポールドル","chf"=>"スイスフラン");
$ret="<table class='waihui'>\n";
$ret.="<tr><th colspan='3'>".$result['date']."</th></tr>\n";
foreach($result as $key=>$value){
if($key=='date'){
continue;
}
$ret.="<tr><td>1 <img src='images/country/".$key.".gif' width='25' height='14' border='0' alt='".$name[$key]."' align='absmiddle'></td>\n";
$ret.="<td width='20px;' align='center'>=</td>\n";
$ret.="<td>".$value." RMB</td></tr>\n";
}
$ret .= "<tr><td><input type='text' size='4' name='from'></td>";
$ret .= "<td colspan='2'><select name='fromtype'>";
foreach($name as $value=>$name){
if($value=='donotwant'){
continue;
}
$ret .= "<option value='".$value."'>".$name."</option>";
}
$ret .= "</select></td></tr>\n";
$ret .= "<tr><td><input type='text' size='4' name='to' readonly='true'></td><td>RMB</td><td><input type='button' value='計算する' class='button' onclick='javascript:calc();'></tr>\n";
$ret .= "</table>\n";
$ret .= "<script language='javascript'>\n";
$ret .= "function calc(){\n";
$ret .= "\trate=new Array();\n";
$ret .= "\ttype=document.getElementById('fromtype').value;\n";
$ret .= "\tf=document.getElementById('from');\n";
$ret .= "\tt=document.getElementById('to');\n";
foreach($result as $key=>$value){
if($key=="date"){
continue;
}
$ret .= "\trate['".$key."']=".$value.";\n";
}
$ret .= "\tfv=parseInt(f.value);\n";
$ret .= "\tres=fv*rate[type];\n";
$ret .= "\tres=res.toString();\n";
$ret .= "\tendpos=res.indexOf('.')\n";
$ret .= "\tif(endpos>0){\n";
$ret .= "\t\tendpos=endpos+3;";
$ret .= "\t\tt.value=res.substr(0,endpos);\n";
$ret .= "\t}else{\n";
$ret .= "\t\tt.value=res;\n";
$ret .= "\t}\n";
$ret .= "}";
$ret .= "</script>\n";
return $ret;
}
function showWaihui(){
global $mosConfig_absolute_path;
$today = date("Y-m-d");
$path = $mosConfig_absolute_path."/tmp/";
$default = "waihui_default.html";
$lastNew = "waihui_".$today.".html";
// if(file_exists($path.$lastNew)){
//$content = @file_get_contents($path.$lastNew);
// }else{
$result = getWaihui();
if(count($result)==0||empty($result)){
//if(file_exists($path.$default)){
// $content = @file_get_contents($path.$default);
//}else{
// $content = "无法获取";
//}
}else{
$content = format($result);
//$file = @fopen($path.$lastNew,'w');
//fwrite($file,$content);
//fclose($file);
//$file = @fopen($path.$default,'w');
//fwrite($file,$content);
//fclose($file);
}
// }
return $content;
}
echo showWaihui();
function filterArray(&$object) {
if(is_array($object)) {
$object=array_filter($object,"filterArray");
$ret=count($object)==0?false:true;
return $ret;
}
if(is_string($object)){
$ret=trim($object)==""?false:true;
return $ret;
}
$ret=gettype($object)==null||$object==null?false:true;
return $ret;
}
?>
执行文件2就是执行文件1中的注释去掉就可以。