本篇文章給大家分享的是有關(guān)如何在php中使用explode函數(shù)對字符串進行分割,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
//利用 explode 函數(shù)分割字符串到數(shù)組
復制代碼 代碼如下:
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串
$hello = explode(',',$source);
for($index=0;$index
echo $hello[$index];echo "";
}
?>
//split函數(shù)進行字符分割
// 分隔符可以是斜線,點,或橫線
復制代碼 代碼如下:
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year
\n";
?>
通過數(shù)組實現(xiàn)多條件查詢的代碼
復制代碼 代碼如下:
$keyword="asp php,jsp";
$keyword=str_replace(" "," ",$keyword);
$keyword=str_replace(" ",",",$keyword);
$keyarr=explode(',',$keyword);
for($index=0;$index
$whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') ";
}
echo $whereSql;
以上就是如何在php中使用explode函數(shù)對字符串進行分割,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降?。希望你能通過這篇文章學到更多知識。更多詳情敬請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。