strstr("母字符串", "子字符串")用来查找子字符串在母字符串中第一次出现的位置,并返回母字符串中从子字符串开始到母字符串结束的部分。比如
php字符串分割(explode str_split preg_split
php教程 explode() 函数
php string 函数
定义和用法
explode() 函数把字符串分割为数组。
语法
explode(separator,string,limit)参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。
php 字符串长度函数
php strlen() 函数
定义和用法
strlen() 函数返回字符串的长度。
语法
strlen(string)参数 描述
string 必需。规定要检查的字符串。
php 读取文件函数
1、用file_get_contents或者fopen、file、readfile等函数读取url的时候,会创建一个名为$http_response_header的变量来保存http响应的报头,使用fopen等函数打开的数据流信息可以用stream_get_meta_data来获取。
二款php文件上传程序
$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 filter_input函数
在 php教程5.2 中,内置了filter 模块,用于变量的验证和过滤。
过滤变量等操作可以参看我原先提及的,这里我们看下如何直接过滤用户输入的内容。
sqlite 数据库连接类
*/
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);
}
php创建文件函数
* 写入函数
* writer(文件名,写入数据, 写入数据方式);
*/
php把内容中图片连接地址替换成自己的
$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);
经典php分页代码(支持数字偏移)(1/2)
</style>
<?php
mysql_connect('localhost','root','');
mysql_select_db('news');
mysql_query('set names gbk');
字符串截取函数(支持中英文混体)
字符串截取函数(支持中英文混体)
以前我们截取字符串都会用php教程自带的函数,今天我来看一下一款字符串截取函数(支持中英文混体)的php代码实例吧。
*/
删除目录及目录下所有文件
/