-
-
$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
- ?>
-
Copy code
Instructions:
There is a problem when using the above code: there will be problems when using ',' (comma) as the delimiter.
Please be careful when using it.
|