有關php分割字符串explode函數的用法,使用explode函數將字符串分割到數組,這裡給大家總結了幾個示例,需要的朋友參考下。
PHP數組和explode函數應用實例,供大家學習參考。
例1:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 <?php $province = array("北京","上海","天津","重慶","河北","山西","內蒙古","遼寧","吉林","黑龍江","江蘇","浙江","安徽","福建","江西","山東","河南","湖北","湖南","廣東","廣西","海南","四川","貴州","雲南","西藏","陝西","甘肅","寧夏","青海","新疆","香港","澳門","台灣","其他"); echo count($province);//數組成員個數 echo "<br/>"; if(is_array($province)){//檢測變量是否是數組 echo "嗯,真是個數組啊"; } echo "</br>"; for($index=0;$index<count($province);$index++){//數組循環 echo $province[$index]; echo "</br>"; } ?>例2:
?
1 2 3 4 5 6 7 8 9 <?php //利用 explode 函數分割字符串到數組 $source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串 $hello = explode(',',$source); for($index=0;$index<count($hello);$index++){ echo $hello[$index];echo "</br>"; } ?>例3:
?
1 2 3 4 5 6 7 <?php //函數挺實用的 // 分隔符可以是斜線,點,或橫線 $date = "04/30/1973"; list($month, $day, $year) = split ('[/.-]', $date); echo "Month: $month; Day: $day; Year: $year<br />n"; ?>以上所述就是本文的全部內容了,希望大家能夠喜歡。
注< >:更多精彩教程請關注三聯編程