对uchome2.0 的function_common.php的研究2

阅读更多

 

在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[] = "/\   
 

$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 "";
	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

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(PHP,IE,XML,浏览器,Ajax)