php 字串轉數組

來源:互聯網
上載者:User

 
 $str = "corn, broccoli, zucchini";
 $ar = explode(", ", $text);
 print_r($ar);
 /*
 定義和用法
 explode() 函數把字串分割為數組。
 
 文法
 explode(separator,string,limit)參數 描述
 separator 必需。規定在哪裡分割字串。
 string 必需。要分割的字串。
 limit 可選。規定所返回的數組元素的最大數目。
*/ 
 
 $biuuu = 'www.111cn.net';
 print_r(str_split($biuuu)) 
 /*
 定義和用法
 str_split() 函數把字串分割到數組中。
 
 文法
 str_split(string,length)參數 描述
 string 必需。規定要分割的字串。
 length 可選。規定每個數組元素的長度。預設是 1。
*/
 
 //
 $str="$str=$str;";
 eval($str);
 
 $string = '杯子';
 $name = '咖啡';
 $str = '這個 $string 中裝有 $name.<br>';
 echo $str;
 eval( "$str = "$str";" );
 echo $str;

 //eval eval()函數的作用是:返回與php代碼相對應的字串。
 
 
 $str="1:0:1:0:1";
 $arraylist=split(":",$str); //存入數組
 
 for($i=0;$i<count($arraylist);$i++) //把它們全部輸出來
 {
 echo $arraylist[$i]."   ";
 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.