-1

Let's say my request url:

http://google.com?asdgeez~user=USERNAME~hash=SECRET_TOKKEN

I wanna select data like $data[1], $data[2], $data[3] It should look like:

Array
(
    [0] => http://google.com?asdgeez
    [1] => USERNAME
    [2] => SECRET_TOKKEN
)

So basically it needs to remove ~user= and ~hash= part. For feature usage it helps me validate each value separately.

Any ideas how to do it ?

Till Helge
  • 9,253
  • 2
  • 40
  • 56
ZeroSuf3r
  • 1,961
  • 8
  • 25
  • 36

3 Answers3

0

Well...you could try it like this:

 $data = preg_split('#~(:?\w+=)?#', $_SERVER['REQUEST_URI']);
Till Helge
  • 9,253
  • 2
  • 40
  • 56
0

Try using regexp:

$input = 'http://google.com?asdgeez~user=USERNAME~hash=SECRET_TOKKEN';
preg_match('/^(.*?)~\w+=(.*?)~\w+=(.*)$/', $input, $matches);

var_dump($matches);

/*
array(4) {
  [0]=>
  string(58) "http://google.com?asdgeez~user=USERNAME~hash=SECRET_TOKKEN"
  [1]=>
  string(25) "http://google.com?asdgeez"
  [2]=>
  string(8) "USERNAME"
  [3]=>
  string(13) "SECRET_TOKKEN"
}
*/
hsz
  • 148,279
  • 62
  • 259
  • 315
  • It's very good, but how about this char # ? If it exist, array just gone :/ – ZeroSuf3r Nov 04 '11 at 12:37
  • @Zero You didn't mention about it. In which place can it be ? – hsz Nov 04 '11 at 12:48
  • In article found answer, http://stackoverflow.com/questions/4865604/how-do-i-detect-remove-and-redirect-urls-with-a-at-the-end-in-php It's clien-side, not server. Markink as solved. Thanks. – ZeroSuf3r Nov 04 '11 at 18:10
0
$uri = "http://google.com?asdgeez~user=USERNAME~hash=SECRET_TOKKEN";

$str1 = explode('~user=', $uri);
$str2 = explode('~hash=', $str1[1]);

$final = array_merge($str1[0], $str2[0], $str2[1]);
pankar
  • 1,623
  • 1
  • 11
  • 21