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! 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; ?> 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! 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
Archived
This topic is now archived and is closed to further replies.