php中數(shù)組首字符過濾功能代碼
更新時間:2012年07月31日 22:29:33 作者:
php數(shù)組中需要對數(shù)組按首字符過濾,通過下面的代碼實現(xiàn)了,需要的朋友可以參考下
復制代碼 代碼如下:
<?php
$array = array(
'abcd',
'abcde',
'bcde',
'cdef',
'defg',
'defgh'
);
$str = '~'.implode('~',$array).'~';
$word = $_GET['word']; //url = xxx.php?word=a
preg_match_all("/~({$word}(?:[^~]*))/i",$str,$matches);
var_dump($matches[1]);
//輸出
//array(2) { [0]=> string(4) "abcd" [1]=> string(5) "abcde" }
//End_php
另:這段代碼發(fā)現(xiàn)了一個奇怪的問題:分隔符使用','(逗號)的時候會出現(xiàn)問題。
相關文章
深入file_get_contents與curl函數(shù)的詳解
本篇文章是對file_get_contents與curl函數(shù)進行了詳細的分析介紹,需要的朋友參考下2013-06-06

