首页 > phper

php字符串分割(explode str_split preg_split

php教程 explode() 函数
php string 函数
定义和用法
explode() 函数把字符串分割为数组。

语法
explode(separator,string,limit)参数 描述
separator 必需。规定在哪里分割字符串。
string 必需。要分割的字符串。
limit 可选。规定所返回的数组元素的最大数目。

阅读全文

php字符串比较函数

比较两个字符串是否相等,最常见的方法就是使用“===”来判断,至于它和“==”的区别,简单来说就是前者强调“identical”类型也要求一样;后者要求“equal”,值相同就可以了,参考【1】。或者使用strcmp来判断,但是这个能够告诉你两个字符串是否相等,但是无法告诉你在那里不同。我的思路是单字符串分割为一个个字母(character),这样比较就能精确知道在那个位置不同了。分隔字符串,使用“str_split”就可以了,语法参考【2】。然后输出结果数组,好处是连空格也会作为数组的元素。我之前的例子就是因为前一个字符串包含2个空格,而后一个只有一个。但是输出的时候看到的显示都是一样的。 也可以按照其他分隔符进行分割,如“explode”或者“preg_split”,

阅读全文

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把内容中图片连接地址替换成自己的

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

阅读全文

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);
  }

阅读全文