我必须使用curl
将字符串中包含单引号的值发布到网址,单引号自动剥离我认为,如何在使用curl
时在字符串中正确包含单引号,
$url = "test.com/req?a=10&b='1010','1012'";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
答案 0 :(得分:2)
使用urlencode。
$url = "test.com/req?a=10&b=" . urlencode("'1010','1012'");
答案 1 :(得分:0)
这样您就可以构建任何复杂性的查询字符串:
$url = 'test.com/req';
$query = array(
'a' => 10,
'b' => "'1010','1012'"
);
$url .= '?'. http_build_query($query);
// will produce this
// test.com/req?a=10&b=%271010%27%2C%271012%27