当前位置:  编程技术>php
本页文章导读:
    ▪php去掉字符串的最后一个字符附substr()的用法       今天项目中用到,去掉字符串中的最后一个字符 原字符串1,2,3,4,5,6, 去掉最后一个字符",",最终结果为1,2,3,4,5,6 代码如下: 代码如下: $str = "1,2,3,4,5,6,"; $newstr = substr($str,0,strlen($str)-1); echo $ne.........
    ▪PHPUnit PHP测试框架安装方法       单元测试是几个现代敏捷开发方法的基础,使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成来自动测试,最后它还可.........
    ▪开启CURL扩展,让服务器支持PHP curl函数(远程采集)       curl()、file_get_contents()、snoopy.class.php这三个远程页面抓取或采集中用到的工具,默迹还是侵向于用snoopy.class.php,因为他效率比较高且不需要服务器特定配置支持,在普通虚拟主机中即可使用.........

[1]php去掉字符串的最后一个字符附substr()的用法
    来源: 互联网  发布时间: 2013-11-30
今天项目中用到,去掉字符串中的最后一个字符
原字符串1,2,3,4,5,6,
去掉最后一个字符",",最终结果为1,2,3,4,5,6
代码如下:
代码如下:

$str = "1,2,3,4,5,6,";
$newstr = substr($str,0,strlen($str)-1);
echo $newstr;


解读:
采用php的substr()方法,
语法: string substr(string string, int start, int [length]);
参数1:原字符串;
参数2:切割的起始位置;
参数3:截取的长度;

按这样来使用:
$newstr = substr($str,0,strlen($str)-1);
从开头截取,一直截取到倒数第二位,这样就把最后的","去掉了。


系统自带的函数也可实现这样的效果,两种方法:
1) substr($str, 0, -1)
2)rtrim($str, ",")

substr
取部份字符串。
语法: string substr(string string, int start, int [length]);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数将字符串 string 的第 start 位起的字符串取出 length 个字符。若 start 为负数,则从字符串尾端算起。若可省略的参数 length 存在,但为负数,则表示取到倒数第 length 个字符。
使用范例
代码如下:

<?
echo substr("abcdef", 1, 3); // 返回 "bcd"
echo substr("abcdef", -2); // 返回 "ef"
echo substr("abcdef", -3, 1); // 返回 "d"
echo substr("abcdef", 1, -1); // 返回 "bcde"
?>


PHP rtrim() 函数

定义和用法
rtrim() 函数从字符串的末端开始删除空白字符或其他预定义字符。同chop()函数。

语法
参数 描述 string 必需。规定要转换的字符串。 charlist

可选。规定从字符串中删除哪些字符。

如果未设置该参数,则全部删除以下字符:

  • "\0" - ASCII 0, NULL
  • "\t" - ASCII 9, 制表符
  • "\n" - ASCII 10, 新行
  • "\x0B" - ASCII 11, 垂直制表符
  • "\r" - ASCII 13, 回车
  • " " - ASCII 32, 空格

使用范例

    
[2]PHPUnit PHP测试框架安装方法
    来源: 互联网  发布时间: 2013-11-30
单元测试是几个现代敏捷开发方法的基础,使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成来自动测试,最后它还可以和Selenium整合来完成大型的自动化集成测试。

Windows平台LAMP环境XAMPP 1.7.3下如何安装PHPUnit呢?

首先,以管理员身份运行cmd,使用pear添加phpunit频道:

D:\xampp\php>pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized

频道添加好,尝试安装PHPUnit:

D:\xampp\php>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHPUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/DbUnit requires PEAR Installer (version >= 1.9.1), installed version is1.9.0
phpunit/DbUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/File_Iterator requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_CodeCoverage requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
phpunit/PHP_CodeCoverage requires package "phpunit/File_Iterator" (version >= 1.2.2)
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
phpunit/PHPUnit_MockObject requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHPUnit_Selenium requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_TokenStream requires PEAR Installer (version >= 1.9.1), installed version is 1.9.0
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
No valid packages found
install failed

从提示看出,需要安装PEAR 1.9.1,而当前PEAR是1.9.0,那就要先升级PEAR版本。

pear list-upgrades可以列出当前可用的更新,
D:\xampp\php>pear.bat list-upgrades
WARNING: channel "pear.php.net" has updated its protocols, use "pear channel-update pear.php.net" to
update

D:\xampp\php>pear channel-update pear.php.net
Updating channel "pear.php.net"
Update of Channel "pear.php.net" succeeded

D:\xampp\php>pear.bat list-upgrades
PEAR.PHP.NET AVAILABLE UPGRADES (STABLE):
=========================================
CHANNEL PACKAGE LOCAL REMOTE SIZE
pear.php.net Archive_Tar 1.3.3 (stable) 1.3.7 (stable) 17.2kB
pear.php.net Console_Getargs 1.3.4 (stable) 1.3.5 (stable) 17.8kB
pear.php.net Mail 1.1.14 (stable) 1.2.0 (stable) 23kB
pear.php.net Mail_Mime 1.5.2 (stable) 1.8.1 (stable) 31kB
pear.php.net Mail_mimeDecode 1.5.1 (stable) 1.5.5 (stable) 11.4kB
pear.php.net Net_SMTP 1.3.4 (stable) 1.4.4 (stable) 12.1kB
pear.php.net Net_Socket 1.0.9 (stable) 1.0.10 (stable) 5.3kB
pear.php.net PEAR 1.9.0 (stable) 1.9.1 (stable) 287kB
pear.php.net Structures_Graph 1.0.3 (stable) 1.0.4 (stable) 30kB
Channel pear.phpunit.de: No upgrades available
ZEND.GOOGLECODE.COM/SVN AVAILABLE UPGRADES (STABLE):
====================================================
CHANNEL PACKAGE LOCAL REMOTE SIZE
zend.googlecode.com/svn zend 1.9.6 (stable) 1.11.1 (stable) -

更新所有可用更新:
D:\xampp\php>pear upgrade-all
Will upgrade channel://pear.php.net/archive_tar
Will upgrade channel://pear.php.net/console_getargs
Will upgrade channel://pear.php.net/mail
Will upgrade channel://pear.php.net/mail_mime
Will upgrade channel://pear.php.net/mail_mimedecode
Will upgrade channel://pear.php.net/net_smtp
Will upgrade channel://pear.php.net/net_socket
Will upgrade channel://pear.php.net/pear
Will upgrade channel://pear.php.net/structures_graph
Will upgrade channel://zend.googlecode.com/svn/zend
Did not download optional dependencies: pear/Auth_SASL, use --alldeps to download automatically
pear/Net_SMTP can optionally use package "pear/Auth_SASL"
downloading Archive_Tar-1.3.7.tgz ...
Starting to download Archive_Tar-1.3.7.tgz (17,610 bytes)
......done: 17,610 bytes
downloading Console_Getargs-1.3.5.tgz ...
Starting to download Console_Getargs-1.3.5.tgz (18,207 bytes)
...done: 18,207 bytes
downloading Mail-1.2.0.tgz ...
Starting to download Mail-1.2.0.tgz (23,214 bytes)
...done: 23,214 bytes
downloading Mail_Mime-1.8.1.tgz ...
Starting to download Mail_Mime-1.8.1.tgz (31,530 bytes)
...done: 31,530 bytes
downloading Mail_mimeDecode-1.5.5.tgz ...
Starting to download Mail_mimeDecode-1.5.5.tgz (11,554 bytes)
...done: 11,554 bytes
downloading Net_SMTP-1.4.4.tgz ...
Starting to download Net_SMTP-1.4.4.tgz (12,264 bytes)
...done: 12,264 bytes
downloading Net_Socket-1.0.10.tgz ...
Starting to download Net_Socket-1.0.10.tgz (5,429 bytes)
...done: 5,429 bytes
downloading PEAR-1.9.1.tgz ...
Starting to download PEAR-1.9.1.tgz (293,587 bytes)
...done: 293,587 bytes
downloading Structures_Graph-1.0.4.tgz ...
Starting to download Structures_Graph-1.0.4.tgz (30,318 bytes)
...done: 30,318 bytes
downloading Zend-1.11.1.tgz ...
Starting to download Zend-1.11.1.tgz (3,638,888 bytes)
...done: 3,638,888 bytes
upgrade-all ok: channel://pear.php.net/Archive_Tar-1.3.7
upgrade-all ok: channel://pear.php.net/Console_Getargs-1.3.5
upgrade-all ok: channel://pear.php.net/Mail-1.2.0
upgrade-all ok: channel://pear.php.net/Mail_Mime-1.8.1
upgrade-all ok: channel://pear.php.net/Net_Socket-1.0.10
upgrade-all ok: channel://pear.php.net/Structures_Graph-1.0.4
upgrade-all ok: channel://zend.googlecode.com/svn/Zend-1.11.1
upgrade-all ok: channel://pear.php.net/Mail_mimeDecode-1.5.5
upgrade-all ok: channel://pear.php.net/Net_SMTP-1.4.4
upgrade-all ok: channel://pear.php.net/PEAR-1.9.1
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"

更新成功后,PEAR已经是1.9.1版了,现在可以放心地安装PHPUnit了:

D:\xampp\php>pear install phpunit/PHPUnit
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: pear.symfony-project.com
Unknown remote channel: components.ez.no
Unknown remote channel: components.ez.no
phpunit/PHPUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/DbUnit requires package "channel://pear.symfony-project.com/YAML" (version >= 1.0.2)
phpunit/PHP_CodeCoverage requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
phpunit/PHP_TokenStream requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
downloading File_Iterator-1.2.3.tgz ...
Starting to download File_Iterator-1.2.3.tgz (3,406 bytes)
....done: 3,406 bytes
downloading PHPUnit_MockObject-1.0.3.tgz ...
Starting to download PHPUnit_MockObject-1.0.3.tgz (17,333 bytes)
...done: 17,333 bytes
downloading PHPUnit_Selenium-1.0.1.tgz ...
Starting to download PHPUnit_Selenium-1.0.1.tgz (15,285 bytes)
...done: 15,285 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.2.3
install ok: channel://pear.phpunit.de/PHPUnit_MockObject-1.0.3
install ok: channel://pear.phpunit.de/PHPUnit_Selenium-1.0.1

上面信息来看,还是没有安装成功,pear.symfony-project.com和components.ez.no两个频道也要添加一下:

D:\xampp\php>pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded

D:\xampp\php>pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

再次尝试安装PHPUnit:

D:\xampp\php>pear install phpunit/PHPUnit
phpunit/PHPUnit can optionally use PHP extension "dbus"
phpunit/PHP_CodeCoverage can optionally use PHP extension "xdebug" (version >= 2.0.5)
downloading PHPUnit-3.5.5.tgz ...
Starting to download PHPUnit-3.5.5.tgz (116,148 bytes)
....................done: 116,148 bytes
downloading DbUnit-1.0.0.tgz ...
Starting to download DbUnit-1.0.0.tgz (38,183 bytes)
...done: 38,183 bytes
downloading PHP_CodeCoverage-1.0.2.tgz ...
Starting to download PHP_CodeCoverage-1.0.2.tgz (109,280 bytes)
...done: 109,280 bytes
downloading YAML-1.0.4.tgz ...
Starting to download YAML-1.0.4.tgz (9,919 bytes)
...done: 9,919 bytes
downloading ConsoleTools-1.6.1.tgz ...
Starting to download ConsoleTools-1.6.1.tgz (869,994 bytes)
...done: 869,994 bytes
downloading PHP_TokenStream-1.0.1.tgz ...
Starting to download PHP_TokenStream-1.0.1.tgz (7,250 bytes)
...done: 7,250 bytes
downloading Base-1.8.tgz ...
Starting to download Base-1.8.tgz (236,357 bytes)
...done: 236,357 bytes
install ok: channel://pear.symfony-project.com/YAML-1.0.4
install ok: channel://components.ez.no/Base-1.8
install ok: channel://pear.phpunit.de/DbUnit-1.0.0
install ok: channel://components.ez.no/ConsoleTools-1.6.1
install ok: channel://pear.phpunit.de/PHP_TokenStream-1.0.1
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-1.0.2
install ok: channel://pear.phpunit.de/PHPUnit-3.5.5

PHPUnit安装成功!!!

    
[3]开启CURL扩展,让服务器支持PHP curl函数(远程采集)
    来源: 互联网  发布时间: 2013-11-30
curl()、file_get_contents()、snoopy.class.php这三个远程页面抓取或采集中用到的工具,默迹还是侵向于用snoopy.class.php,因为他效率比较高且不需要服务器特定配置支持,在普通虚拟主机中即可使用,file_get_contents()效率稍低些,常用失败的情况、curl()效率挺高的,支持多线程,不过需要开启下curl扩展。下面是curl扩展开启的步骤:

  1、将PHP文件夹下的三个文件php_curl.dll,libeay32.dll,ssleay32.dll复制到system32下;

  2、将php.ini(c:WINDOWS目录下)中的;extension=php_curl.dll中的分号去掉;

  3、重启apache或者IIS。

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php四舍五入的三种实现方法 iis7站长之家
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3