0
votes

Anyone can help me, how to get all the words inside slash of the $_SERVER['QUERY_STRING']

For example:

I have here url:

http://www.domain.com/controller/method?param1/param2/param3/param4

then i use

$_SERVER['QUERY_STRING'];

to get this result

param1/param2/param3/param4

my question is how can i get all the words that ends with slash.

i have here my code below but my preg_match get all words the ends with ";" symbol.

here is my code

$str = "param1;param2;param3;param4";
preg_match_all('/;(?P<words>\s*\w+[\w\s\-\.\*\:\(\)]*)/',$str,$match);
$result = $match['words'];
  foreach($result as $value){
    echo '<p><b>'.$value.'</b></p>';
  }

Result

param1

param2

param3

My question is:

here is my param: param1/param2/param3/param4

how can i get all param word and the result like this:

param1

param2

param3

param4

Thanks in advance.

1

1 Answers

0
votes

Easy with explode() and implode()

$params = explode('/', $_SERVER['QUERY_STRING']); // returns array of all params 
print_r($params);
echo implode(' ', $params); //param1 param2 param3 param4