Wednesday 15 May 2013

php - Extract parameter from a string -



php - Extract parameter from a string -

i have extract string this:

index.php?module=reports&action=abc&rname=instantpayment

now task extract report, action , rname value in php.

i have tried using explode(), not able extract module.

how can it?

you utilize parse_str() in case:

$string = 'index.php?module=reports&action=abc&rname=instantpayment'; $string = substr($string, strpos($string, '?')+1); // string after question mark until end of string parse_str($string, $data); // utilize function, stress free echo '<pre>'; print_r($data);

should output:

array ( [module] => reports [action] => abc [rname] => instantpayment )

php string

No comments:

Post a Comment