ho risolto cosi :

preg_match("/(p=)(.*?)(&)/",$refer,$regs);
$chiave= $regs[2];