-3
$request = '/test.php?action=save&key=e7s2uHhKKtcM32cHKUKM&login=test';
$param = preg_match("#^test.php?action=save&key=(\w+)&login=(\w+)($)#", $request, $match);
print_r($param);

It's not working. How to fix?

mega6382
  • 9,211
  • 17
  • 48
  • 69
user3608884
  • 59
  • 1
  • 6

1 Answers1

-1
  1. You need to escape your preg control characters "." and "?"
  2. You are matching ^test meaning the string should start with "test", while your string starts with "/test"
  3. I highly recommend to use single ticks so you don't have to escape your escape characters "\".

    $param = preg_match('#^/test\.php\?action=save&key=(\w+)&login=(\w+)($)#', $request, $match);
    print_r($param); // 1
    print_r($match); // Array (
    // (
    //     [0] => /test.php?action=save&key=e7s2uHhKKtcM32cHKUKM&login=test
    //     [1] => e7s2uHhKKtcM32cHKUKM
    //     [2] => test
    //     [3] => 
    // )
    
Xyz
  • 5,955
  • 5
  • 40
  • 58