php中利用explode函數(shù)分割字符串到數(shù)組
更新時(shí)間:2014年02月08日 15:54:51 作者:
這篇文章主要介紹了php中利用explode函數(shù)分割字符串到數(shù)組,需要的朋友可以參考下
分割字符串
//利用 explode 函數(shù)分割字符串到數(shù)組
<?php
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++)
{
echo $hello[$index];echo "</br>";
}
?>
//split函數(shù)進(jìn)行字符分割
// 分隔符可以是斜線,點(diǎn),或橫線
<?php
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
通過數(shù)組實(shí)現(xiàn)多條件查詢的代碼
<?php
$keyword="asp php,jsp";
$keyword=str_replace(" "," ",$keyword);
$keyword=str_replace(" ",",",$keyword);
$keyarr=explode(',',$keyword);
for($index=0;$index<count($keyarr);$index++)
{
$whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') ";
}
echo $whereSql;
//利用 explode 函數(shù)分割字符串到數(shù)組
復(fù)制代碼 代碼如下:
<?php
$source = "hello1,hello2,hello3,hello4,hello5";//按逗號分離字符串
$hello = explode(',',$source);
for($index=0;$index<count($hello);$index++)
{
echo $hello[$index];echo "</br>";
}
?>
//split函數(shù)進(jìn)行字符分割
// 分隔符可以是斜線,點(diǎn),或橫線
復(fù)制代碼 代碼如下:
<?php
$date = "04/30/1973";
list($month, $day, $year) = split ('[/.-]', $date);
echo "Month: $month; Day: $day; Year: $year<br />\n";
?>
通過數(shù)組實(shí)現(xiàn)多條件查詢的代碼
復(fù)制代碼 代碼如下:
<?php
$keyword="asp php,jsp";
$keyword=str_replace(" "," ",$keyword);
$keyword=str_replace(" ",",",$keyword);
$keyarr=explode(',',$keyword);
for($index=0;$index<count($keyarr);$index++)
{
$whereSql .= " And (arc.title like '%$keyarr[$index]%' Or arc.keywords like '%$keyarr[$index]%') ";
}
echo $whereSql;
相關(guān)文章
php正則preg_replace_callback函數(shù)用法實(shí)例
這篇文章主要介紹了php正則preg_replace_callback函數(shù)用法,實(shí)例分析了preg_replace_callback函數(shù)進(jìn)行正則替換的相關(guān)技巧,需要的朋友可以參考下2015-06-06PHP程序員最常犯的11個(gè)MySQL錯(cuò)誤小結(jié)
對于大多數(shù)web應(yīng)用來說,數(shù)據(jù)庫都是一個(gè)十分基礎(chǔ)性的部分。如果你在使用PHP,那么你很可能也在使用MySQL—LAMP系列中舉足輕重的一份子。2010-11-11使用PHPMailer實(shí)現(xiàn)郵件的實(shí)時(shí)發(fā)送功能
這篇文章主要為大家詳細(xì)介紹了如何使用PHPMailer 實(shí)現(xiàn)一個(gè)接收詢盤并實(shí)時(shí)同步到指定郵箱的功能,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-12-12PHP不使用內(nèi)置函數(shù)實(shí)現(xiàn)字符串轉(zhuǎn)整型的方法示例
一般php字符串類型的數(shù)字如果想轉(zhuǎn)成整型的數(shù)字,我們都是采用系統(tǒng)內(nèi)置的API去做轉(zhuǎn)換,但下面這篇文章主要給大家介紹了關(guān)于PHP不使用內(nèi)置函數(shù)實(shí)現(xiàn)字符串轉(zhuǎn)整型的方法示例,文中介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-07-07PHP橋接模式Bridge Pattern的優(yōu)點(diǎn)與實(shí)現(xiàn)過程
這篇文章主要介紹了PHP橋接模式Bridge Pattern的優(yōu)點(diǎn)與實(shí)現(xiàn)過程,橋接模式是一種結(jié)構(gòu)型模式,它將抽象部分與實(shí)現(xiàn)部分分離開來,使它們可以獨(dú)立地變化2023-03-03利用php獲取服務(wù)器時(shí)間的實(shí)現(xiàn)代碼
本篇文章是對使用php獲取服務(wù)器時(shí)間的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06