Copy code The code is as follows:
$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]);
//output
//array(2) { [0]=> string(4) "abcd" [1]=> string(5) "abcde" }
//End_php
Another: This code was found A strange problem: problems occur when using ',' (comma) as the delimiter.
http://www.bkjia.com/PHPjc/325796.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325796.htmlTechArticleCopy the code as follows: ?php $array = array( 'abcd', 'abcde', 'bcde', 'cdef', 'defg', 'defgh' ); $str = '~'.implode('~',$array).'~'; $word = $_GET['word']; //url = xxx .php?word=...