在vim中调试php, 安装php code_sniffer,php-md. phpqa.vim
1:安装php code sniffer 和 php md
php code sniffer
a: centos系的
#yum install php-pear
#yum install ImageMagick-devel
#pear install PHP_CodeSniffer
#pear channel-discover pear.phpmd.org
#pear channel-discover pear.pdepend.org
#pear install --alldeps phpmd/PHP_PMD
修改php.ini文件,加入extension=imagick.so
debian系的
#apt-get install php-pear
#apt-get install php5-imagick imagemagick
后面和上面centos的一样,
只是不需要修改php.ini 加入imagick 扩展.
2:vim 里面
:!php -l % 这个是检查当前php文件语法参数
:phpcs 这个就是code sniffer了
:phpmd 这个是mess detector , 需要一个XML规则文件如果没有设置
:phpcc 这个显示code coverage. 也需要一个XML规则文件如果没有设置
3:安装phpqa.vim
https://github.com/rainysia/vimrc/commits/master
去clone下来,放到$~.vim里面, 注意是user下面的.vim
在.vimrc里面加上
let g:phpqa_codesniffer_args = "--standard=Zend" let g:phpqa_codesniffer_cmd = '/usr/bin/phpcs' let g:phpqa_codesniffer_autorun = 1 " default =1 on save let g:phpqa_messdetector_ruleset = '' let g:phpqa_messdetector_cmd = '/usr/bin/phpmd' let g:phpqa_messdetector_autorun = 0其中cmd 这两个是上面第一步安装后 type出来的路径,
#type phpcs
/usr/bin/phpcs
autorun = 1是自动开启 ,当你保存的时候就会自动运行提示了
<?xml version="1.0"?> <ruleset name="Sebastian" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:nonamespaceschemalocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description>Sebastian Bergmann's ruleset</description> <rule ref="rulesets/codesize.xml/CyclomaticComplexity"></rule> <rule ref="rulesets/codesize.xml/NPathComplexity"></rule> <rule ref="rulesets/codesize.xml/ExcessiveClassComplexity"></rule> <rule ref="rulesets/codesize.xml/ExcessiveClassLength"></rule> <rule ref="rulesets/codesize.xml/ExcessiveMethodLength"></rule> <rule ref="rulesets/codesize.xml/ExcessiveParameterList"></rule> <rule ref="rulesets/design.xml/EvalExpression"></rule> <rule ref="rulesets/design.xml/ExitExpression"></rule> <rule ref="rulesets/design.xml/GotoStatement"></rule> <rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"></rule> <rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"></rule> <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"></rule> <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"></rule> <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"></rule> </ruleset>
现在做下测试,打开vim 输入<?php ?> 然后:w保存,提示错误,说php不能关闭..看来语法要求很严格. 去掉?> 然后保存就没错误提示了.
<?php ?>
具体的可以在shell里面 -h 查看使用
参考网址
http://phpmd.org/download/index.html 安装phpmd
http://pear.php.net/package/PHP_CodeSniffer/redirected php code sniffer
http://blog.csdn.net/xinhaozheng/article/details/3324796 php code sniffer的使用
http://developer.51cto.com/art/201105/261292.htm php mess detor的使用
http://coreymaynard.com/blog/finding-what-stinks-and-cleaning-up-the-mess/ 相关xml声明
http://joncairns.com/2012/05/using-vim-as-a-php-ide/#comment-133 phpqa的文章
https://github.com/joonty/vim-phpqa 还是phpqa的

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function