scooter41 Posted August 13, 2008 Share Posted August 13, 2008 Hey There! I am just trying to create a search system using URL rewrites, however the number of name/value pairs are unknown. So the country variable may exist by itself, and with keywords for example, or they may just search by keywords. I couldnt find any successful code to "loop through" an unknown number in the URL string, so I decided to pass all to php and process that way, for example: RewriteRule ^villas/(.*) /listVillas.php?urls=$1 So villas/page/2/country/3/ would transfer to /listVillas.php?urls=page/2/country/3/ Is there an expresssion that would split this into $page=2, $country=3 for an infinite number of name+value pairs? Thanks for any help in advance! Quote Link to comment https://forums.phpfreaks.com/topic/119440-url-rewrite-with-unknown-namevalue-pairs/ Share on other sites More sharing options...
sasa Posted August 13, 2008 Share Posted August 13, 2008 try <?php $_GET['urls'] = 'page/2/country/3/'; $tmp = explode('/',trim($_GET['urls'],'/')); for ($i = 0; $i < count($tmp); $i++){ $$tmp[$i++] = $tmp[$i]; } echo $page, ' - ', $country; ?> Quote Link to comment https://forums.phpfreaks.com/topic/119440-url-rewrite-with-unknown-namevalue-pairs/#findComment-615335 Share on other sites More sharing options...
scooter41 Posted August 13, 2008 Author Share Posted August 13, 2008 perfect! Works great thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119440-url-rewrite-with-unknown-namevalue-pairs/#findComment-615413 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.