doug007 Posted February 5, 2010 Share Posted February 5, 2010 hi guys, give this string ?page=home how would you match/get anything after the = sign? thanks Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 5, 2010 Share Posted February 5, 2010 there are ways to do this without regex and you should use them before regex, regex is for pattern matching.. Using regex will always be a slower alternative, so if there IS an alternative you should use it but the regex would be /^?[^=]+=(.*)$/ Quote Link to comment Share on other sites More sharing options...
doug007 Posted February 5, 2010 Author Share Posted February 5, 2010 thanks men. Quote Link to comment Share on other sites More sharing options...
doug007 Posted February 5, 2010 Author Share Posted February 5, 2010 ok this isn't working it errors out: Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 1 $pattern='/^?[^=]+=(.*)$/'; if(preg_match($pattern, "home", $matches)){ //$this->page=$this->urlpage; var_dump($matches); } Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted February 5, 2010 Share Posted February 5, 2010 Yup. parse_str() would be a better choice example $str = '?page=home'; $str = ltrim($str, '?'); parse_str($str, $array); echo $array['page']; Quote Link to comment Share on other sites More sharing options...
doug007 Posted February 5, 2010 Author Share Posted February 5, 2010 Yup. parse_str() would be a better choice example $str = '?page=home'; $str = ltrim($str, '?'); parse_str($str, $array); echo $array['page']; Thanks Jay. parse_str is a nice little function Quote Link to comment Share on other sites More sharing options...
RussellReal Posted February 5, 2010 Share Posted February 5, 2010 also sorry, you would have needed to escape the ? as ? is a quantifier. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.