php - How do I randomly jumble sections of a URL seperated by "/"? -
i’m wondering how jumble sections of url /
separator:
http://fujifilm.in/en/products/consumer_products/digital_cameras/x/fujifilm_x_t1/
i’m looking combinations of results, like
http://fujifilm.in/en/products/consumer_products/digital_cameras/x/fujifilm_x_t1/ http://fujifilm.in/en/products/consumer_products/digital_cameras/x http://fujifilm.in/en/products/consumer_products/digital_cameras http://fujifilm.in/en/products/consumer_products http://fujifilm.in/en/products http://fujifilm.in/en/ http://fujifilm.in/ http://fujifilm.in/en/fujifilm_x_t1/ http://fujifilm.in/en/products/fujifilm_x_t1/ http://fujifilm.in/en/products/consumer_products/fujifilm_x_t1/ http://fujifilm.in/en/products/consumer_products/digital_cameras/fujifilm_x_t1/ ................ ................ ................
how can this?
this should started:
$uri = 'http://fujifilm.in/en/products/consumer_products/digital_cameras/x/fujifilm_x_t1/'; $parts = parse_url($uri); $path = $parts['path']; $sections = explode('/', $path); foreach ($sections $k => $v) { if (!$v) { unset($sections[$k]); } } shuffle($sections); echo $parts['scheme'] . '://' . $parts['host'] . '/' . implode('/', $sections) . '/' . php_eol;
the above outputs 1 random permutation of url path. tweaking shuffle()
function give possible outputs, , putting echo
in foreach
loop should reasonably straightforward. started here’s question getting possible permutations of string. changing work arrays shouldn’t difficult.
Comments
Post a Comment