Home  >  Q&A  >  body text

javascript - Get the form through file_get_content("php://input") in the background, how to parse the complete value with parameters

<form>
<input type="text" name="goods_name" value="西瓜500g">
<input type="text" name="origin_url" value="https://www.baidu.com?page=50&since=2015">
<input type="text" name="price" value="10.0">
</form>

The backend is received through file_get_content("php://input"). How to parse the complete three values ​​​​of goods_name, origin_url, and price?
There is a solution on the Internet that uses ‘&’ as ​​the node to cut through explode, but if you do this, the origin_url will get

“https://www.baidu.com?page=50” 

There is also an extra since field instead of the complete

“https://www.baidu.com?page=50&since=2015”

Does anyone know of any method that can completely parse the url value with parameters?

漂亮男人漂亮男人2671 days ago766

reply all(2)I'll reply

  • 迷茫

    迷茫2017-05-31 10:36:53

    $queryString = parse_url($url, PHP_URL_QUERY);
    parse_str($queryString, $params);
    var_dump($params);

    Thank you for pointing it out. I haven’t used these two functions for a long time. I forgot that parse_str directly receives the return value in the parameter = =

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-31 10:36:53

    Thank you very much, the source code is like this,
    $packData=urldecode(file_get_contents( "php://input" ));
    parse_str($packData,$params);//The parse_str function has no return value, so $params = parse_str($queryString); is the wrong way to write it
    //var_dump($param);

    reply
    0
  • Cancelreply