php中数组首字符过滤功能代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?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

另:这段代码发现了一个奇怪的问题:分隔符使用','(逗号)的时候会出现问题。

相关文章

PHP内置加密函数详解

Md5()加密算法 方式: 单向加密 语法: md5(string $str [, bool $raw_output = false]) $str:原始字符串 $raw_output:如...

php中magic_quotes_gpc对unserialize的影响分析

本文实例分析了php中magic_quotes_gpc对unserialize的影响。分享给大家供大家参考。具体如下: magic_quotes_gpc是一个php中一个给单双引号增加一...

php检测文本的编码

通过对文本的一次循环编码,来判断是否属于该编码。 public function chkCode($string) { $code = array( 'ASCII...

thinkphp使用phpmailer发送邮件的方法

本文实例讲述了thinkphp使用phpmailer发送邮件的方法。分享给大家供大家参考。具体分析如下: phpmailer发送邮件是php开发者首选的一个邮件发送插件了,下面我来介绍怎...

shopex主机报错误请求解决方案(No such file or directory)

一、shopex主机环境 1、windows 2003 R2 2、iis6.0+php5.0以上 3、mysql5.0以上 如果有希望了解php环境搭配的,请查阅: windows200...