PHP常用函數

來源:互聯網
上載者:User

標籤:

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()函數。

 

PHP常用函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.