一、修改 php.ini 加载路径php
添加环境变量 ,新建系统变量 PHPRC ,配置以下:html
检验: 经过phpinfo(),查看系统配置web
Loaded Configuration File ,识别系统当前加载的有效php.ini文件路径ajax
二、配置composer 出现错误json
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify服务器
解决方法:yii2
CA证书下载地址:http://curl.haxx.se/docs/caextract.htmlcomposer
而后修改php.ini文件yii
openssl.cafile= D:/php/verify/cacert.pemcurl
离线包
http://files.cnblogs.com/files/rhythmK/php_pem.rar
composer爆错:zlib_decode():data error
#先运行所有返回OK,而后再到代码composer.json目录执行后面命令 composer diagnose composer install -vvv
三、php 实现 startWith endWith
1 //第一个是原串,第二个是 部份串 2 function startWith($str, $needle) { 3 4 return strpos($str, $needle) === 0; 5 6 } 7 8 //第一个是原串,第二个是 部份串 9 function endWith($haystack, $needle) { 10 11 $length = strlen($needle); 12 if($length == 0) 13 { 14 return true; 15 } 16 return (substr($haystack, -$length) === $needle); 17 }
四、让指定域支持ajax请求[待测试]
<?php header("Access-Control-Allow-Origin:http://blog.rhythmk.com"); //容许blog.rhythmk.com提交访问 //header("Access-Control-Allow-Origin:*"); //容许任何访问 echo json_encode($_POST);
五、让IDE可以在View层进行智能提示,需先在页注释中声明对象类型:
/* @var $this yii\web\View */ /* @var $model source\models\Menu */ /* @var $form yii\widgets\ActiveForm * /* @var $num integer */
六、在控制台输出汉字转码并换行:
private function writeLineMsg($msg) { $str=iconv("UTF-8", "GB2312", $msg); echo $str."\n"; }
七、strpos(字符串,查询字符,搜索启始位)
查询到指定字符则从0开始返回索引位 不然返回false。
if(strpo('abcdefg','a')!==false) { echo 'find'; }else { echo 'no find'; }
八、include \ reguire 区别
在 PHP 中,您能够在服务器执行 PHP 文件以前在该文件中插入一个文件的内容。
include 和 require 语句用于在执行流中插入写在其余文件中的有用的代码。
include 和 require 除了处理错误的方式不一样以外,在其余方面都是相同的:
九、让sublime text 支持编译 php
一、工具-》编译系统-》新建编译系统,输入以下代码,保存成 php.sublime-build
{ "cmd": ["php", "$file"], "file_regex": "php$", "selector": "source.php" }
二、工具-》编译系统-》 选择php ,而后按ctrl+b 运行代码。
参考:http://jingyan.baidu.com/article/09ea3ede04ebe9c0aede390d.html?qq-pf-to=pcqq.group
十、 URL 编码 解码
urlencode urldecode
十一、方法前面添加@,则屏蔽方法内部抛出的异常。好的代码是不推荐使用这种方式去屏蔽错误的。
<?php function test($value) { return 10/$value; } //echo test(0); //Warning: Division by zero in C:\php_demo\demo2.php on line 24 echo @test(0); ?>
十二、PHP的Global变量的做用是定义全局变量,可是这个全局变量不是应用于整个网站,而是应用于当前页面,包括include或require的全部文件。
1.$GLOBALS['var']是外部的全局变量自己
2.global $var是外部$var的同名引用或者指针。
<?php $GLOBALS['var1'] = 5; $var2 = 1; function get_value(){ global $var2; $var1 = 0; return $var2++; } get_value(); echo $var1; echo $var2; ?>
1三、list 使用
list($a,$b)=['aaa','bbb','ccc']; print_r($a); // aaa print_r($b); // bbb
yii2 笔记:
一、使用命令启动YII2,使用cmd命令行切换到YII 目录,运行yii.bat ,运行命令以下
yii controller/action , 如: yii home/index
若是该action 附带参数则 按参数顺序,以空格分割传入数值便可。 如 yii home/index 值1 值2