201710 PHP 函数回顾

来源:互联网 发布:spss for mac安装教程 编辑:程序博客网 时间:2024/06/05 22:35

1、strpos

mixed strpos ( string $haystack , mixed $needle [, int $offset = 0 ] )

Find the numeric position of the first occurrence of needle in the haystack string.

查找$needle在字符串$haystack中出现的位置。

特别注意可能返回位置0以及查找不到的时候返回false,所以比较的时候注意要用===或者!==

$offset代表偏移量,例如下面的例子,返回值是7而不是0

<?php// We can search for the character, ignoring anything before the offset$newstring = 'abcdef abcdef';$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0?>
2、

basename(__FILE__)

basename() 函数返回路径中的文件名部分。


详细用法再研究


3 str_replace()

<?phpecho str_replace("world","Shanghai","Hello world!");?>

//Hello Shanghai!

4 dirname()

函数返回路径中的目录部分。

<?phpecho dirname("c:/testweb/home.php");echo dirname("/testweb/home.php");?>
//

c:/testweb/testweb

5string getcwd ( void )


获得当前的工作目录


substr() 函数返回字符串的一部分。

注释:如果 start 参数是负数且 length 小于或等于 start,则 length 为 0。