Page 1 of 1
Preg_match returning numbers?
Posted: Tue Mar 18, 2008 4:34 pm
by Citizen
Code: Select all
$searchType = "title";
$tempkey = "sgame.title.foobar";
$pattern = '/sgame' . $searchType . '.(.*?)/';
preg_match($pattern, $tempkey, $matches, PREG_OFFSET_CAPTURE);
print_r($matches);
Prints this:
Code: Select all
Array ( [0] => Array ( [0] => title. [1] => 6 ) [1] => Array ( [0] => [1] => 12 ) )
I'm looking to put 'foobar' into a variable that I can then use, but all that comes up are these numbers. Any ideas?
Re: Preg_match returning numbers?
Posted: Tue Mar 18, 2008 6:10 pm
by scriptah
Code: Select all
$pattern = '/sgame\.' . $searchType . '\.?(.*)?/';
I think you have a problem with your pattern ...
Re: Preg_match returning numbers?
Posted: Tue Mar 18, 2008 8:15 pm
by John Cartwright
RTM
preg_match(..., PREG_OFFSET_CAPTURE); wrote:If this flag is passed, for every occurring match the appendant string offset will also be returned. Note that this changes the return value in an array where every element is an array consisting of the matched string at index 0 and its string offset into subject at index 1.
Re: Preg_match returning numbers?
Posted: Wed Mar 19, 2008 1:29 pm
by Citizen
I read the manual, but I didn't quite understand the implication of the offset_capture, which is why i came here
And thanks to both of you, the correction of the pattern and removal of offset did the trick.
-Cit