iSE Posted August 26, 2010 Share Posted August 26, 2010 Hi, I'm interested in sending the REQUEST_URI variable to a MySQL database, and retrieving the data for that particular page. The problem is that since all the URL's are dynamically changing, only part of the REQUEST_URI may be specified in the database. So for instance, the REQUEST_URI may be: /holdcroft-renault-hanley/used-cars/2/4/price-asc/ And the request_uri fields in the database will be something like: /holdcroft-renault-hanley/used-cars/ /new-cars/ /used-cars/ /holdcroft-renault-hanley/ /price-asc/ What I need to do, is to create a regex pattern so that preg_match_all will be able to get every possible combination of /(.*)/. I've been trying various different methods and patterns only to keep on getting stuck. So far I have: preg_match_all('/\/?(.*)\/?/', $_SERVER['REQUEST_URI'], $matchesArray); var_dump($matchesArray); and this gives me: array(2) { [0]=> array(2) { [0]=> string(50) "/holdcroft-renault-hanley/used-cars/2/4/price-asc/" [1]=> string(0) "" } [1]=> array(2) { [0]=> string(49) "holdcroft-renault-hanley/used-cars/2/4/price-asc/" [1]=> string(0) "" } } What I want to get, is an array filled with every possibility, so: /holdcroft-renault-hanley/used-cars/2/4/price-asc/ /holdcroft-renault-hanley/used-cars/2/4/ /holdcroft-renault-hanley/used-cars/2/ /holdcroft-renault-hanley/used-cars/ /holdcroft-renault-hanley/ /used-cars/2/4/price-asc/ /used-cars/2/4/ /used-cars/2/ /used-cars/ /2/4/price-asc/ /2/4/ /2/ /4/price-asc/ /4/ /price-asc/ are all the possible matches, how do I create a regular expression to collect these results? As always, all help is very much appreciated, and indeed passed on. Regards, iSE Quote Link to comment Share on other sites More sharing options...
ZachMEdwards Posted August 27, 2010 Share Posted August 27, 2010 I don't really understand the question, but is this what you are looking for? $pattern = '%/^(.*)$/%m'; Quote Link to comment Share on other sites More sharing options...
sasa Posted August 28, 2010 Share Posted August 28, 2010 ttry <?php $test = '/holdcroft-renault-hanley/used-cars/2/4/price-asc/'; $a = perm($test); print_r($a); function perm($a){ $out = array(); $a = explode('/', trim($a, '/')); $a1 = $a; if ($a[0] ){ while (count($a)){ $out[] = '/'. implode('/', $a).'/'; array_pop($a); } array_shift($a1); $c = perm(implode('/', $a1)); $out = array_merge($out, $c); } return $out; } ?> 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.