您的位置:首页 > 编程语言 > PHP开发

PHP函数

2015-11-02 15:20 519 查看

PHP函数

标签(空格分隔): PHP

[TOC]

strtr 字符串替换

string strtr ( string $str , string $from , string $to )
string strtr ( string $str , array $replace_pairs )

对指定字符串
$str
将里面的
$from
替换为
$to


参数 replace_pairs 可以用来取代 to 和 from 参数,因为它是以 array('from' => 'to', ...) 格式出现的数组。

<?php
$trans  = array( "hello"  =>  "hi" ,  "hi"  =>  "hello" );
echo  strtr ( "hi all, I said hello" ,  $trans );
?>

以上例程会输出:

hello all, I said hi

glob 文件遍历

glob()
函数依照 libc
glob()
函数使用的规则寻找所有与 pattern 匹配的文件路径,类似于一般 shells 所用的规则一样。不进行缩写扩展或参数替代。

<?php
foreach(glob("*.php") as $list){
if(is_file($list)) echo $list.'<br/>';
}

输出:

01obj_1.php

02obj_lianshi_capzuo.php

03obj_duotai.php

04and.php
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: