Nare
11-26-2007, 05:29 PM
Hi, Im trying to write a function and pass an argument that will be used by preg_match. can't get it to work and this seems to be where my problem is:
$subject="54,1,2,3,51,55,4,5,6,5";
$pattern ='/[,]*5[^\d]/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
//output: Array ( [0] => Array ( [0] => 5, [1] => 13 ) )
$lookfor = "5";
$pattern = "'/[,]*".$lookfor."[^\d]/'";
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
//output: Array ( )
print_r($pattern);
//output: '/[,]*5[^\d]/'
Pattern is the same in both cases, so what am I missing here?
$subject="54,1,2,3,51,55,4,5,6,5";
$pattern ='/[,]*5[^\d]/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
//output: Array ( [0] => Array ( [0] => 5, [1] => 13 ) )
$lookfor = "5";
$pattern = "'/[,]*".$lookfor."[^\d]/'";
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
//output: Array ( )
print_r($pattern);
//output: '/[,]*5[^\d]/'
Pattern is the same in both cases, so what am I missing here?