php中對字符串的基本操作

(1)分割字符串

//利用 explode 函數分割字符串到數組 

<?php
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串 
$hello = explode(',',$source);

for($index=0;$index<count($hello);$index++)
{
echo $hello[$index];echo "</br>"; 
} 
?> 

//split函數進行字符分割 
// 分隔符可以是斜線,點,或橫線 

<?php
$date = "04/30/1973"; 
list($month, $day, $year) = split ('[/.-]', $date); 
echo "Month: $month; Day: $day; Year: $year<br />\n"; 
?>



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章