Get the url parameters in php

2019-10-06 17:24发布

I have a url :

http://localhost:17080/SMSService/Getsms.php?to=100001&body=6260575535299&from=09350000008

‏ and I want to get the value of "to" , "body" , "from" . how can I do this in php? Thanks a lot

4条回答
何必那么认真
2楼-- · 2019-10-06 17:40

you can try the below..

<?php
   echo $_GET['to'];  
   echo $_GET['body'];  
   echo $_GET['from'];  
?>
查看更多
Luminary・发光体
3楼-- · 2019-10-06 17:43

I'm not sure, but maybe OP wants just to parse an url. It could be something like this then:

#!/usr/bin/php
<?php
$url = "http://localhost:17080/SMSService/Getsms.aspx?to=100001&body=6260575535299&from=09350000008";
$url_parts = parse_url($url);
parse_str($url_parts['query'], $path_parts);

echo($path_parts['to']."\n");
echo($path_parts['body']."\n");
echo($path_parts['from']."\n");
?>

and output is:

100001
6260575535299
09350000008
查看更多
来,给爷笑一个
4楼-- · 2019-10-06 17:45

Use the $_GET superglobal:

if (array_key_exists('body', $_GET))
  echo $_GET['body'];

But this is really simple stuff. The beginners tutorial in the Getting Started section on PHP.net already covers superglobals (although they start with $_SERVER rather than $_GET). If you desire to learn PHP quickly, it will pay to read a couple of those before asking questions like this.

查看更多
神经病院院长
5楼-- · 2019-10-06 17:54

It is really simple.

<?php
$to = $_GET['to'];
$from = $_GET['from'];
......// and so on...
?>

For this to work, you need to store it in a php file. Read more about this : http://www.php.net/manual/en/reserved.variables.get.php

查看更多
登录 后发表回答