php array first character filter function code

  • 2020-05-19 04:21:10
  • OfStack

 
<?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]); 

// The output  
//array(2) { [0]=> string(4) "abcd" [1]=> string(5) "abcde" } 
//End_php 

Also: this code has found a strange problem: the use of the ',' (comma) delimiter causes problems.

Related articles: