首页 > PHP教程

php 实现文章上一页与下一页 代码

php 实现文章上一页与下一页 代码,这是我要写一个小作品时用到了,今天把它拿出来各各位分享一下下,记得以前我总想法不明白怎么实现文章上下一页的做法,后来在一个BBS看到了原来是判断当前ID然后order by 或asc就可以简单的实现了.

阅读全文

php 字符截取与图片过滤函数

本文章免费为各位朋友提供一款哦,如果你喜欢的话不防进来看看这款图片过滤正则表达试

function msubstr($str, $start, $len) {
 $tmpstr = "";
 $strlen = $start + $len;
 for($i = 0; $i < $strlen; $i++) {
       if(ord(substr($str, $i, 1)) > 0xa0) {
         $tmpstr .= substr($str, $i, 2);
         $i++;
       } else
         $tmpstr .= substr($str, $i, 1);
  }
 return $tmpstr;
 }
 
 //过滤图片
 function img_empty($content){
  $content=eregi_replace("<IMG ([a-zA-Z0-9~!& ?:"/._#=~&%]+)>","",$content);
  return $content;
 }

阅读全文

php 域名处理函数

下面这款个一个是判断输入的域名是不是合法的,然后再把http,https,ftp进行处理,分析再发送

function _scan_url()
   {
       $req = $this->_url;
      
       $pos = strpos($req, '://');
       $this->_protocol = strtolower(substr($req, 0, $pos));
      
       $req = substr($req, $pos+3);
       $pos = strpos($req, '/');
       if($pos === false)
           $pos = strlen($req);
       $host = substr($req, 0, $pos);
      
       if(strpos($host, ':') !== false)
       {
           list($this->_host, $this->_port) = explode(':', $host);
       }
       else
       {
           $this->_host = $host;
           $this->_port = ($this->_protocol == 'https') ? 443 : 80;
       }
      
       $this->_uri = substr($req, $pos);
       if($this->_uri == '')
           $this->_uri = '/';
   }

阅读全文

php 读取远程网站内容[反盗连]

这是一款利用php fsockopen来读取远程服务器的内容哦,下面这段程序的做法就是可以反盗连呢,好了下面来看看吧。

 function DownloadToString()
   {
       $crlf = "rn";
       $response="";
       // generate request
       $req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
           .    'Host: ' . $this->_host . $crlf
           .    $crlf;
      
       // fetch
       $this->_fp = @fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
       @fwrite($this->_fp, $req);
       while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
           $response .= fread($this->_fp, 1024);
       @fclose($this->_fp);
      
       // split header and body
       $pos = strpos($response, $crlf . $crlf);
       if($pos === false)
           return($response);
       $header = substr($response, 0, $pos);
       $body = substr($response, $pos + 2 * strlen($crlf));
      
       // parse headers
       $headers = array();
       $lines = explode($crlf, $header);
       foreach($lines as $line)
           if(($pos = strpos($line, ':')) !== false)
               $headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
      
       // redirection?
       if(isset($headers['location']))
       {
           $http = new HTTPRequest($headers['location']);
           return($http->DownloadToString($http));
       }
       else
       {
           return($body);
       }
   }
}

阅读全文