Thursday, March 4, 2010

Programmer - preg_match two variables with metacharacters

Programmer Question

I have two string variables which are both file paths. The code that worked used ereg which is deprecated, so I'm trying to rewrite it using preg_match:



Old code that worked:



$path1 = quotemeta($path);
ereg("$path1(.*)$", $path2, $matches);


Using preg_match which doesn't seem to work:



$path1 = quotemeta($path);
preg_match("/$path1(.*)$/", $path2, $matches);


It gives preg_match(): Unknown modifier 'V' error.



Also, the main thing I'm trying to obtain is $matches[1], which is the text that matched the first captured parenthesized subpattern, so I'm thinking I can't really use substr().



Any help would be greatly appreciated.



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails