Home  >  Article  >  Backend Development  >  PHP知识点小结

PHP知识点小结

WBOY
WBOYOriginal
2016-06-13 13:08:21760browse

PHP知识点总结

?1.?DIRECTORY_SEPARATOR

?

?? ? ? 因为在window上分隔符是"\"而在linux上分隔符是"/" ?使用这个符号就可以避免这个问题。

?

?2.?realpath

?

?? ? ?返回文件所在的绝对路径。

?

?3. 在php中 0==null 是成立的。?? ?

?

?4.file_get_contents和file区别

?

?? ? ? ?file_get_contents将文件内容作为一个字符串返回

?? ? ? ?file ?将文件内容按行读取到一个数组中,一行就是数组中的一项。

?

count(file("test.txt"))//获得文件的行数

?

?

?5. php删除文件夹 (如果有文件夹不为空第一次跑这个文件可能会报错,第二次就可以了)

?

function deleteDir($dir){
    if(rmdir($dir)==false&&is_dir($dir)){
          if($filehandler=opendir($dir)){
                 while(($file=readdir($filehandler))!=false){
                       if($file!="."&&$file!=".."){ 
                             $fullpath = $dir."/".$file;
                             if(is_dir($fullpath)){
                                     deleteDir($fullpath);
                             }else{
                                     unlink($fullpath);
                             }
                        }
                 }
                 closedir($filehandler);
          }else{
                echo "permision deny";
          } 
    }
}

?

6. ?json_encode和json_decode

?

?? ? ? ? ? ?json_encode() ? : ?将一个php对象转化为json格式的字符串

?

?? ? ? ? ? ?json_decode($str,$boolean) ?: ?将json格式字符串转化为一个php对象,如果$boolean为true则返回一个数组。 注意$str的格式一定要正确,key一定要有双引号,否则转化失败。

?

?7. ?php字符串连接使用 .= 符号,不是+=符号。


?8. ?__FILE__ 取得当前文件的绝对地址。

?

?9. ?首先打开php.ini,将zend_extension = "D:\develop\xampp\php\ext\php_xdebug.dll"打开,同时[xdebug]设置项打开相 ? ? ? ? ? 关的设置,只要是 xdebug.remote_enable = On 要打开,不然无法调试。php.ini的xdebug设置如下:、

?

xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_mode=req
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=PhpStorm1
?

?? 设置完毕,启动PhpStorm,我们使用打开目录功能,这里的目录最好是xampp的htdocs下的一个目录,这样我们就可以实时调试程序。接下来我们要打开设置面板,然后选择php,设置正确的php home路径,这里就可以进行php相关的单元测试等。

?

? ?注意xampp安装的路劲不能有空格,不识别。

?

?10. ?php发送邮件 主题乱码解决

?

?

$subject = iconv("","UTF-8","Gaea");
$subject = "=?UTF-8?B?".base64_encode($subject)."?="; //转化成base64
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn