PHP常用函数

1.implode();

implode(separator,array): 返回值(string)=array元素+separator。其中separator参数可选,但为向后兼容,一般都带上。

eg:

<?php

$arr = array('Hello','World!','I','love','Shanghai!');

echo implode(" ",$arr)."<br>";

echo implode("+",$arr)."<br>";

echo implode("-",$arr)."<br>";

echo implode("X",$arr);

?>
运行结果:
Hello World! I love Shanghai!
Hello+World!+I+love+Shanghai!
Hello-World!-I-love-Shanghai!
HelloXWorld!XIXloveXShanghai!

2.explode()

explode(separator,str,limit):返回值(Array)。

Notice:当limit>0,Array.length=limit;

          当limit<0时,Array.length=str.length-1;

          当limit=0时,Array.length=1.

eg:

<?php

$str = 'one,two,three,four';

// 零 limit

print_r(explode(',',$str,0));

// 正的 limit

print_r(explode(',',$str,2));

// 负的 limit

print_r(explode(',',$str,-1));

?>

      运行结果:

Array ( [0] => one,two,three,four )

Array ( [0] => one [1] => two,three,four )

Array ( [0] => one [1] => two [2] => three )

3.get_include_path()

 获取当前默认目录

4.set_include_path()

set_include_path(new_inlcude_path):配置新的路径,使得通过include()函数可以直接访问该路径下的文件,简化了目录计算。

eg:

   <?php
          set_include_path("Website/");
          include("test1.php");
          include("test2.php");
          include("test3.php");
          require("test4.php");
          require("test5.php");
       ?>

5.ob_start()

ob是output buffer的简称。ob_start()用来激活服务器缓冲区。当该函数被调用,除头信息外其余信息均不会输出。

若要输出,则使用相应Flush或bo_end_flush()函数。

 

posted @ 2016-09-06 19:49  南韵  阅读(796)  评论(0编辑  收藏  举报