If you know that the p=### will always be the only argument in the URL, I would use this:
$x="http://www.google.com/?p=23";
preg_match("/\?p=([0-9]+)$/",$x,$regs);
echo $regs[1]."\n\n";
But if the p=### might be in the middle of a list of arguments in the URL like this:
http://www.google.com/?x=1&y=2&p=23&z=17
then I would use something like this:
$x="http://www.google.com/?x=1&p=23&z=123";
preg_match("/[^a-zA-Z]p=([0-9]+)/",$x,$regs);
echo $regs[1]."\n\n";
These are called Regular Expressions. They are good for finding stuff in strings.