在common.php里,有这么一段代码
//启用GIP if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) { ob_start('ob_gzhandler'); } else { ob_start(); }
如果服务器支持gzip的话,那么就调用
ob_start('ob_gzhandler');
ob_start的意思是开始数据缓冲,也就是服务器的echo的东西会放在缓冲区里不会直接发送给浏览器。ob_gzhandler是作为回调函数来调用的。关于此函数解释为
ob_gzhandler() is intended to be used as a callback function for ob_start() to help facilitate sending gz-encoded data to web browsers that support compressed web pages. Before ob_gzhandler() actually sends compressed data, it determines what type of content encoding the browser will accept ("gzip", "deflate" or none at all) and will return its output accordingly. All browsers are supported since it's up to the browser to send the correct header saying that it accepts compressed web pages. If a browser doesn't support compressed pages this function returns FALSE .
而ob_start的那个callback参数的解释如下
When output_callback is called, it will receive the contents of the output buffer as its parameter and is expected to return a new output buffer as a result, which will be sent to the browser.
也即使说支持gzip的服务器会在把数据传到浏览器之前先把数据传给那个回调函数产生新的输出。ob_gzhandler一定就是压缩数据的方法了。
在function_common里有这么一个函数
ob_out
//调整输出 function ob_out() { global $_SGLOBAL, $_SCONFIG, $_SC; $content = ob_get_contents(); $preg_searchs = $preg_replaces = $str_searchs = $str_replaces = array(); if($_SCONFIG['allowrewrite']) { $preg_searchs[] = "/\<a href\=\"space\.php\?(uid|do)+\=([a-z0-9\=\&]+?)\"/ie"; $preg_searchs[] = "/\<a href\=\"space.php\"/i"; $preg_searchs[] = "/\<a href\=\"network\.php\?ac\=([a-z0-9\=\&]+?)\"/ie"; $preg_searchs[] = "/\<a href\=\"network.php\"/i"; $preg_replaces[] = 'rewrite_url(\'space-\',\'\\2\')'; $preg_replaces[] = '<a href="space.html"'; $preg_replaces[] = 'rewrite_url(\'network-\',\'\\1\')'; $preg_replaces[] = '<a href="network.html"'; } if($_SCONFIG['linkguide']) { $preg_searchs[] = "/\<a href\=\"http\:\/\/(.+?)\"/ie"; $preg_replaces[] = 'iframe_url(\'\\1\')'; } if($_SGLOBAL['inajax']) { $preg_searchs[] = "/([\x01-\x09\x0b-\x0c\x0e-\x1f])+/"; $preg_replaces[] = ' '; $str_searchs[] = ']]>'; $str_replaces[] = ']]>'; } if($preg_searchs) { $content = preg_replace($preg_searchs, $preg_replaces, $content); } if($str_searchs) { $content = trim(str_replace($str_searchs, $str_replaces, $content)); } obclean(); if($_SGLOBAL['inajax']) { xml_out($content); } else{ if($_SCONFIG['headercharset']) { @header('Content-Type: text/html; charset='.$_SC['charset']); } echo $content; if(D_BUG) { @include_once(S_ROOT.'./source/inc_debug.php'); } } }
$content = ob_get_contents()为取得缓冲区的内容,在obclean之前都是在做字符串的替换,具体的我也不清楚是怎么搞的。
调用ob_clean()把缓冲区里的数据清楚掉。
如果是ajax请求,那么就返回一个数据的xml形式。
其余情况则很正常地把结果echo出去。你会发现在每一个daat下的tpl缓存页面文件里都有一个ob_out()函数。
贴一下相关函数的代码
function obclean() { global $_SC; ob_end_clean(); if ($_SC['gzipcompress'] && function_exists('ob_gzhandler')) { ob_start('ob_gzhandler'); } else { ob_start(); } }
function xml_out($content) { global $_SC; @header("Expires: -1"); @header("Cache-Control: no-store, private, post-check=0, pre-check=0, max-age=0", FALSE); @header("Pragma: no-cache"); @header("Content-type: application/xml; charset=$_SC[charset]"); echo '<'."?xml version=\"1.0\" encoding=\"$_SC[charset]\"?>\n"; echo "<root><![CDATA[".trim($content)."]]></root>"; exit(); }
2、sstripslashes
//去掉slassh function sstripslashes($string) { if(is_array($string)) { foreach($string as $key => $val) { $string[$key] = sstripslashes($val); } } else { $string = stripslashes($string); } return $string; }
这里就是递归地将数组里的字符串反转义,也就是原来是123\'123的现在变成123'123