php教程 explode() 函数
php string 函数
定义和用法
explode() 函数把字符串分割为数组。
语法
explode(separator,string,limit)参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。
php教程 explode() 函数
php string 函数
定义和用法
explode() 函数把字符串分割为数组。
语法
explode(separator,string,limit)参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。
strstr("母字符串", "子字符串")用来查找子字符串在母字符串中第一次出现的位置,并返回母字符串中从子字符串开始到母字符串结束的部分。比如
比较两个字符串是否相等,最常见的方法就是使用“===”来判断,至于它和“==”的区别,简单来说就是前者强调“identical”类型也要求一样;后者要求“equal”,值相同就可以了,参考【1】。或者使用strcmp来判断,但是这个能够告诉你两个字符串是否相等,但是无法告诉你在那里不同。我的思路是单字符串分割为一个个字母(character),这样比较就能精确知道在那个位置不同了。分隔字符串,使用“str_split”就可以了,语法参考【2】。然后输出结果数组,好处是连空格也会作为数组的元素。我之前的例子就是因为前一个字符串包含2个空格,而后一个只有一个。但是输出的时候看到的显示都是一样的。 也可以按照其他分隔符进行分割,如“explode”或者“preg_split”,
addslashes: 字符串加入斜线。
bin2hex: 二进位转成十六进位。
1、用file_get_contents或者fopen、file、readfile等函数读取url的时候,会创建一个名为$http_response_header的变量来保存http响应的报头,使用fopen等函数打开的数据流信息可以用stream_get_meta_data来获取。
php strlen() 函数
定义和用法
strlen() 函数返回字符串的长度。
语法
strlen(string)参数 描述
string 必需。规定要检查的字符串。
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
foreach($_files[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == upload_err_ok){
$f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_files[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']
在 php教程5.2 中,内置了filter 模块,用于变量的验证和过滤。
过滤变量等操作可以参看我原先提及的,这里我们看下如何直接过滤用户输入的内容。
</style>
<?php
mysql_connect('localhost','root','');
mysql_select_db('news');
mysql_query('set names gbk');
$files ='<img src="http://img.phprm.com/img/bid_v2/bid_v2_content/p_bid.gif" alt="普通任务" /><img width="272px" height="60px" style="padding-top: 10px;" src="http://img.imgzhubajie.com/img/index_v3/20100611001.gif">';
// 图片地址转换一下 $p=preg_replace('//image//', 'http://qq.ip138.com/image/', $pg[1]);
$reg = "/<img[^>]*src="(http://(.+)/(.+).(jpg|gif|bmp|bnp))"/isu";
$img=preg_match_all($reg,$files,$imgs);
* 写入函数
* writer(文件名,写入数据, 写入数据方式);
*/
*/
class db_class {
var $conn=null;
var $querynum = 0;
/**
* 数据库连接,返回数据库连接标识符
*
* @param string $ 数据库服务器主机
* @param string $ 数据库服务器帐号
* @param string $ 数据库服务器密码
* @param string $ 数据库名
* @param bool $ 是否保持持续连接,1为持续连接,0为非持续连接
* @return link_identifier $dbuser, $dbpw, $dbname,
*/
function connect($dbhost, $pconnect = 0) {
$error = '';
$func = $pconnect == 1 ? 'sqlite_popen' : 'sqlite_open';
if (!$this -> conn = $func($dbhost, 0666, $error)) {
$this -> halt($error);
}