Jesper Posted June 6, 2009 Share Posted June 6, 2009 Hey guys, For my latest project, I need to find the something in an expression. The expression is: gamenieuws/([0-9]+)/?.* The problem is that at the end of the expression there can be another GET variable, so it would end with something like ?&var=val. I don't want to replace this with the regexp. I've managed so far to find the question mark, but it replaces the string until 1 char before the ?, instead of it replaces it until the ?. My regexp is now: gamenieuws/([0-9]+)/?(.[^\?])* ?item=$1 The problem It might be hard to understand, and I find it hard to explain as well. Anyways, this is what I want: Find gamenieuws/([0-9]+)/.*, but then I want to pass on the get variables as well. For example, I want gamenieuws/123/Lorem-Ipsum-Dolor-Sit-Amet.html?&val1=25&val2=4 to become ?item=123&val1=25&val2=4. Could anyone help me with how to do this, because I've been trying for very long and I have no idea . Thanks in advance, Jesper Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/ Share on other sites More sharing options...
jxrd Posted June 6, 2009 Share Posted June 6, 2009 $q_string = '?'.end(explode('?', $url)); Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850468 Share on other sites More sharing options...
Jesper Posted June 6, 2009 Author Share Posted June 6, 2009 Thanks, but the problem is that it's for a .htaccess file. Forget to say that, sorry. Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850471 Share on other sites More sharing options...
jxrd Posted June 6, 2009 Share Posted June 6, 2009 Oh right. Hmm...can't you just put .*? on the end? Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850473 Share on other sites More sharing options...
Jesper Posted June 6, 2009 Author Share Posted June 6, 2009 Yeah, but how would I get the GET data that's after that? So how would I retrieve the val1 and val2 in gamenieuws/123/Lorem-Ipsum-Dolor-Sit-Amet.html?&val1=25&val2=4, as this data has to be passed on as well. Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850477 Share on other sites More sharing options...
jxrd Posted June 6, 2009 Share Posted June 6, 2009 Try this: <pre><?php $str = 'gamenieuws/123/Lorem-Ipsum-Dolor-Sit-Amet.html?&val1=25&val2=4'; preg_match('#gamenieuws/([0-9]+)/([A-Za-z-]+\.html)\?(.*?)$#', $str, $matches); print_r($matches); ?> Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850501 Share on other sites More sharing options...
Jesper Posted June 6, 2009 Author Share Posted June 6, 2009 Thanks, but the problem is that it's for a .htaccess file. Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850515 Share on other sites More sharing options...
jxrd Posted June 6, 2009 Share Posted June 6, 2009 Yeah, I don't mean actually use that code. I'm just giving you an example of the regex to use. Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850540 Share on other sites More sharing options...
Jesper Posted June 7, 2009 Author Share Posted June 7, 2009 Ah, kk, thanks . I've found the problem now, and that is that GET variables are just not part of the replacing when using RewriteRule. I'm using %{QUERY_STRING} for the GET variables now, as I should've in the first place . Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850917 Share on other sites More sharing options...
jxrd Posted June 7, 2009 Share Posted June 7, 2009 Ahh right. urlrewrites have always confused me lol.... Quote Link to comment https://forums.phpfreaks.com/topic/161168-solved-finding-the-question-mark/#findComment-850928 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.