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";//按逗號(hào)分離字符串
$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";
?>
通過(guò)數(shù)組實(shí)現(xiàn)多條件查詢(xú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";//按逗號(hào)分離字符串
$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";
?>
通過(guò)數(shù)組實(shí)現(xiàn)多條件查詢(xú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)文章
詳解WordPress中調(diào)用評(píng)論模板和循環(huán)輸出評(píng)論的PHP函數(shù)
這篇文章主要介紹了WordPress中調(diào)用評(píng)論模板和循環(huán)輸出評(píng)論的PHP函數(shù),分別是comments_template函數(shù)與wp_list_comments函數(shù)的使用,需要的朋友可以參考下2016-01-01
PHP讀取TXT文本內(nèi)容的五種實(shí)用方法小結(jié)
PHP作為一種流行的服務(wù)器端腳本語(yǔ)言,提供了多種方法來(lái)讀取TXT文本內(nèi)容,本文主要為大家詳細(xì)介紹五種不同的PHP方法,希望對(duì)大家有所幫助2024-01-01
php簡(jiǎn)單實(shí)現(xiàn)快速排序的方法
這篇文章主要介紹了php簡(jiǎn)單實(shí)現(xiàn)快速排序的方法,涉及php針對(duì)數(shù)組與字符串的操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-04-04
php數(shù)組索引的Key加引號(hào)和不加引號(hào)的區(qū)別
這篇文章主要介紹了php數(shù)組索引的Key加引號(hào)和不加引號(hào)的區(qū)別,加引號(hào)和不加引號(hào)是有嚴(yán)重的區(qū)別的,需要的朋友可以參考下2014-08-08
深思 PHP 數(shù)組遍歷的差異(array_diff 的實(shí)現(xiàn))
還是部門(mén)無(wú)聊的考題,不過(guò)這次考的是 PHP 的能力。題目如下: 給你兩個(gè)分別有 5000 個(gè)元素的數(shù)組,計(jì)算他們的差集 -- 說(shuō)白了也就是用 PHP 和你認(rèn)為最好的算法實(shí)現(xiàn) array_diff 的算法。初次接到這個(gè)題目,我發(fā)現(xiàn)這非常的簡(jiǎn)單,于是按照以往的經(jīng)驗(yàn)“隨便”寫(xiě)了一個(gè):2008-03-03
PHP 開(kāi)發(fā)環(huán)境配置(Zend Studio)
運(yùn)行Zend Studio安裝文件(ZendStudio-7.1.2.exe) 安裝選項(xiàng)請(qǐng)按照?qǐng)D片中我的選擇。2010-04-04

