技术&日志

php使用记录

what is php ?

内置函数

生成唯一ID-string: uniqid 详细>>
取出URL path部分: $urlArr = parse_url($url); ltrim($urlArr ['path'], '/'); 官方文档 | php解析url
中文字符字数读取: mb_strlen($data['content'],'utf8');
电话号码隐藏: substr_replace($data['mobile'],'******',3,5);

自定义函数

For输出ASCII码

//ASCII码输出
for($i=0;$i<128;$i++){
    echo $i.'=>'.sprintf("%c",$i).'<br />';
}

php配置

递归次数: ini_set('xdebug.max_nesting_level', 2000);

正则

处理电话隐藏 中间六位数用*代替

    public function handleMobile($mobile)
    {
        $pattern1 = "/(1\d{1,2})\d\d(\d{0,3})/";
        $replacement1 = "\$1*****\$3";
        return preg_replace($pattern1, $replacement1, $mobile);
    }

优雅代码

判断如果为空: empty($nickname) && $this->error('请输入昵称');

面象对向

trait-实现多重继承 简明教程 | Trait-特性

Trait 是 PHP5.4 中的新特性,是 PHP 多重继承的一种解决方案。例如,需要同时继承两个 Abstract Class, 这将会是件很麻烦的事情,Trait 就是为了解决这个问题.

问题记录

Q: 伪静态-php5.6或php5.6以下版本不同, php5.6以下这样是没有问题的,但5.6就会出现 No input file specified.
Q: “No input file specified.”,是没有得到有效的文件路径造成的。 更多

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

站内索引

php基础知识