Home > Backend Development > PHP Problem > How to solve curl php post loss problem

How to solve curl php post loss problem

藏色散人
Release: 2023-03-11 13:12:02
Original
2155 people have browsed it

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.

How to solve curl php post loss problem

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 );
Copy after login

$data parameters have two types: string/array

For example: we want to submit two data

$title =  '我是标题';
$content = &#39;<a href="http://www.baidu.com?a=1&b=1">点我百度一下</a>&#39;;
Copy after login

When the type is string

$data = &#39;title=这是标题&content=<a href="http://www.baidu.com?a=1&b=1">点我百度一下</a>&#39;;
Copy after login

After submission, we will find that $_POST['content'] does not appear as we wantClick on Baidu, 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 problem

Recommended 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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template