一、下面介绍一下global.php的函数及使用方法:
1、open()函数,读取远程网页代码不生成缓存,多用于动态页面如搜索之类的页面;
参数说明:open(文件名)或open(文件名,目标文件夹),一般配合URL传递参数使用例如:
<?
require 'commom.php';
$t=$_GET["t"];
$k=$_GET["k"];
$page=$_GET["page"];
if ($page<1)
{
$page=1;
}
$file=open("Search.asp?t=$t&k=$k&page=$page");
?>
参数说明:update(文件名)或update(文件名,目标文件夹),一般都要配合URL传递参数使用(单页面除外);
3、readfromfile()函数,读缓存目录里的文件,并以HTML方式输出,配合update()函数一起使用;
参数说明:readfromfile(文件名),一般都要配合URL传递参数使用(单页面除外)例如:
<?php
require 'commom.php';
update("index.htm");
$file=readfromfile("{$cachefile}/index.htm");
?>
<?php
require 'commom.php';
$list=$_GET["list"];
update("${list}","list");
$file=readfromfile("{$cachefile}/${list}");
?>
4、writetofile()函数,只是供update()函数调用生成缓存文件,后面不会用到只在这里说明一下;
5、cut()函数,字符串截取函数,用于把指定的字符串进行指定的截取;
参数说明:cut(字符串,起始位置,结束位置),字符串一般是以变量来定义例如:
<?php
require 'commom.php';
$list=$_GET["list"];
update("${list}","list");
$file=readfromfile("{$cachefile}/${list}");
$title=cut($file,"<title>","</title>");
?>
注意:如果字符串带有"号的话,要在其前面加上“\”,不然会出错。
6、str_replace()函数,字符串替换函数,查找字符串指定部分内容替换成另一内容;
参数说明:str_replace(查找内容,替换内容,原字符串),例如:
<?php
require 'commom.php';
$list=$_GET["list"];
update("${list}","list");
$file=readfromfile("{$cachefile}/${list}");
$file = str_replace("FilmClass/","FilmClass.php?list=",$file);
?>
好了,这一课就先讲到这里,在下一课我们将做一个PHP电影小偷的实例,敬请留意!
原创文章如转载,请注明:转载自 阳春一月 [ http://blog.ycjan.com/ ]
本文链接地址:http://blog.ycjan.com/php/20090601768.html