Home >Backend Development >PHP Problem >How to solve curl php post loss problem
php curl post data is lost because in the string type, the & symbol is used to separate parameters, so it will cause loss. The solution is to submit it using Array.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the curl php post loss problem?
About the problem of data loss in PHP Curl POST
$ch = curl_init (); curl_setopt ( $ch, CURLOPT_URL, $uri ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data ); $return = curl_exec ( $ch ); curl_close ( $ch );
$data parameters have two types: string/array
For example: we want to submit two data
$title = '我是标题'; $content = '<a href="http://www.baidu.com?a=1&b=1">点我百度一下</a>';
When the type is string
$data = 'title=这是标题&content=<a href="http://www.baidu.com?a=1&b=1">点我百度一下</a>';
After submission, we will find that $_POST['content'] does not appear as we want1552f1ccb0bfbba19f5dd9237290201eClick on Baidu5db79b134e9f6b82c0b36e0489ee08ed, but Array( [title] => 我是标题 [content] => <a href="http://www.baidu.com?a=1 [b] => 1">点我百度一下</a> )
At this time, we only need to use Array to submit and there will be no problemRecommended learning : "PHP Video Tutorial"
The above is the detailed content of How to solve curl php post loss problem. For more information, please follow other related articles on the PHP Chinese website!