随笔分类 - php
摘要:今天有个朋友问我,无乱码截取中文的,我找了找以前的代码,现在po出来,自己看看吧 1 function msubstr($str, $encodeType='utf-8',$start = 0, $length = 20, $hasSuffix = false, $suffix = '。。。') { 2 $res['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; 3 $re
阅读全文
摘要:最近做一个中文匹配,这个匹配的东西不是从数据库里面查出来的,是我固有的中文数组内容做的匹配,1 mb_regex_encoding("UTF-8");2 $reg=$kw;$comment=array('中国','开始时间','梦想','爱你','还在吗','我们','永远');3 foreach($comment as $key => $val){4 mb_ereg_search_init($val, $reg);5 $r = mb_ereg_search
阅读全文
摘要:最近想把session不在单独存储到文件中,想保存到数据库里面,研究了一下:部分代码protected function __construct($save_handler,$save_path,$hash_strategy){ ini_set('session.save_handler',$save_handler); ini_set('memcache.hash_strategy',$hash_strategy); ini_set('session.save_path',$save_path); self::$_mem=new Mem...
阅读全文
摘要:我以前貌似真心没有想过php的命名空间,我每次写文件都会记得不让类名相重,看完命名空间了这个,我发现可以解决我的一部分问题 1 MyLove.php 2 namespace Zj; 3 class Application{ 4 public function toMyLove(){ 5 echo 'Marx is very Painful than English!<br/>'; 6 } 7 } 8 9 MyLover.php10 11 namespace Yaf;12 13 class Application{14 function __c...
阅读全文
摘要:1 $arr[2]='zk';2 $arr[1]=2004;3 $arr[0]=2006;4 foreach($arr as $key => $val){5 echo $key.'==='.$val.'<br/>';6 }在PHP中, 数组是用一种HASH结构(HashTable)来实现的, PHP使用了一些机制, 使得可以在O(1)的时间复杂度下实现数组的增删, 并同时支持线性遍历和随机访问.if 你想在数字索引的数组中按照索引大小遍历, 那么你就应该使用for, 而不是foreach;
阅读全文
摘要:1 curl模拟文件post提交$filePath='d:/www/zjTest/txtFile'; 2 //$filepath = file_get_contents($filePath); 3 $fileName='txtFile'; 4 $data=array('txtFile'=>'@'.$filePath); 5 $url = 'url'; 6 $testurl = curl_init($url); 7 curl_setopt ($testurl, CURLOPT_POST, 1); 8 curl_
阅读全文
摘要:在看php-openid的源码的时候,发现它实现的创建多级目录的方法的思想很巧妙,特将起代码记录下来:/***Createdir_nameasadirectoryifitdoesnotexist.Ifit*exists,makesurethatitis,infact,adirectory.Returns*trueiftheoperationsucceeded;falseifnot.**@accessprivate*/staticfunctionensureDir($dir_name){if(is_dir($dir_name)||@mkdir($dir_name)){returntrue;}el
阅读全文
摘要:1 1. sys_getloadavg() 2 3 sys_getloadavt()可以获得系 统负载情况。该函数返回一个包含三个元素的数组,每个元素分别代表系统再过去的1、5和15分钟内的平均负载。与其让服务器因负 载过高而宕掉,不如在系统负载很高时主动die掉一个脚本,sys_getloadavg()就是用来帮你实现这个功能的。 不过很遗憾,该函数在windows下无效。 4 5 2. pack() 6 7 Pack() 能将md5()返回的32位16进制字符串转换为16位的二进制字符串,可以节省存储空间。 8 9 3. cal_days_in_month() ...
阅读全文
摘要:mixedeval(string$code_str),1 <?php2 $string = 'cup';3 $name = 'coffee';4 $str = 'This is a $string with my $name in it.';5 echo $str. "\n";6 eval("\$str = \"$str\";");7 echo $str. "\n";8 ?>eval 可以把变量值带到语句中输出,如果这个变量在应用之前没有赋予值,那么在ev
阅读全文
摘要:1 $arr=array(33,2,54,25,65,34,67,42,87,90,243,213,365,78,67,345,678); 2 3 function quick_sort($arr){ 4 $len = count($arr); 5 if($len <= 1) 6 { 7 return $arr; 8 } 9 $key = $arr[0]; 10 $arr_left = array(); 11 $arr_right = array(); 12 for ($i=1;$i<$len;$i...
阅读全文
摘要:1 $arr=array(33,2,54,25,65,34,67,42,87,90,243,213,365,78,67,345,678); 2 sort($arr);//二分查找,一定要在一个有序的里面查找 3 sortAll($arr,54); 4 function sortAll($arr,$key,$low='0',$high='0'){ 5 if($high==0){ 6 $high=count($arr); 7 } 8 $mid=intval(($low+$high)/2); 9 if($arr[$mid]==$key){10 ...
阅读全文
摘要:1 <?php 2 3 class grabInfo{ 4 public $content; 5 /*Init 初始化 */ 6 public function __construct($url){ 7 $this->ch=curl_init(); 8 curl_setopt($this->ch,CURLOPT_URL,$url); 9 curl_setopt($this->ch, CURLOPT_RETURNTRANSFER,1); 10 curl_setopt($this->ch,CURL_HEA...
阅读全文
摘要:只有几个常用的,其他的自己可以在网上查到的。text/htmltext/csstext/javascriptimage/gifimage/jpegimage/pngimage/bmpapplication/pdfapplication/x-tarapplication/zipapplication/octet-stream
阅读全文
摘要:php:我在这里就说几个我特别常用的,可能我的这些不是很全,请见谅!$handle=fopen($fileName,$mode),是打开文件,参数看名字知道什么意思了,至于模式,我一般不太建议大家以写模式打开,因为会造成清空文件的后果,所以以写的模式打开慎用。fread($handle,$length);fwrite($handle,$string);fclose($handle); 这几个比较简单,在这里就不过多叙述了feof($handle) 判断指针是否到了文件的末尾,这个可以在以行读取文件,判断文件是否读到末尾fileatime($string),filectime($string),
阅读全文
摘要:看php底层,会发现include_once的工作原理,它是先把文件绝对路径存放在一个大的数组中,我们可以通过get_included_files()得到文件的地址数组,然后在去判断现在要包含的是否已经存在,如果存在则不包含,否则包含。$arr=array();$_SESSION['fpath']=$arr;function myInclude($str){ $flag=in_array(realpath($str),$_SESSION['fpath']); if($flag){ echo 'aaaaaaaaaa';//写自己想要的实现的功能 }
阅读全文
摘要:我的电脑上是nginx+php5+mysql,现在我想在ubuntu上面安装memcached,下面是安装过程,没有出错apt-get install memcachedapt-get install php5-memcache然后sudo service php5-fpm reload,在看phpinfo.php,就可以看到memcached,进行一些memcached优化,在/etc/php5/fpm/conf.d 下面的memcached.ini,里面设置,目前我没有太多的研究,大家可以去google一下
阅读全文
摘要:在空间部署php环境的时候,出现了500错误,这应该是很头疼的一个错误,我用的是cPanel,在控制面板里面查看错误日志,Fri Jan 11 10:45:21 2013] [error] [client 173.255.246.10] File does not exist: /home/wownepie/public_html/500.shtml[Fri Jan 11 10:45:21 2013] [error] [client 211.157.165.186] SoftException in Application.cpp:256: File "/home/wownepie/
阅读全文
摘要:其实myeclipse的插件安装方法大体都一样,就是把下载好的文件夹放到\MyEclipse 8.5\dropins的文件夹下面,一定要记得删除.xml文件,重启myEclipse,myeclipse -> window->preferences -> phpeclipse ->XDebug 下面配置php.exe的目录myeclipse -> window->preferences -> phpeclipse -> php external tools->下面配置apache mysql 目录
阅读全文
摘要:1、最近遇到了个问题,要提取html页面内的div标记里面的全部内容$p="/<div class='box'[^>]*?>(?:.|\s)*?<\/div>/";$p="/<div class='box' .*(.|\n)*?<\/div>/";这两个都是比较好用的,分享给大家2、匹配$str='14:59:58 aa bb cc dd {"show_id":2007,"duration":5}'$str='1
阅读全文

浙公网安备 33010602011771号