[关闭]
@52fhy 2016-02-28T10:12:03.000000Z 字数 562 阅读 447

PHP笔记--函数

PHP


strtr 字符串替换

  1. string strtr ( string $str , string $from , string $to )
  2. string strtr ( string $str , array $replace_pairs )

对指定字符串$str将里面的$from替换为$to
参数 replace_pairs 可以用来取代 to 和 from 参数,因为它是以 array('from' => 'to', ...) 格式出现的数组。

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

以上例程会输出:
hello all, I said hi

glob 文件遍历

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

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

输出:
01obj_1.php
02obj_lianshi_capzuo.php
03obj_duotai.php
04and.php

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注