Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php cURL后不带空格存储的数据_Php_Mysql_Sql Server_Curl_Joomla - Fatal编程技术网

Php cURL后不带空格存储的数据

Php cURL后不带空格存储的数据,php,mysql,sql-server,curl,joomla,Php,Mysql,Sql Server,Curl,Joomla,设置很简单。Joomla电子商务站点(MySQL后端),在创建Joomla帐户后将数据(cURL post)发送到另一个数据库支持的应用程序(ASP和MS SQL) 问题是,有时这些数据存储在接收数据库中,没有任何空格。例如:Joomla站点上收集的地址在数据库中存储为“123 example road”,但在接收数据库中存储为“123 example road”。这并不是一直都会发生,所以我对可能的原因感到困惑 有没有人经历过这样的问题?感谢您的帮助 这就是cURL代码的样子: //creat

设置很简单。Joomla电子商务站点(MySQL后端),在创建Joomla帐户后将数据(cURL post)发送到另一个数据库支持的应用程序(ASP和MS SQL)

问题是,有时这些数据存储在接收数据库中,没有任何空格。例如:Joomla站点上收集的地址在数据库中存储为“123 example road”,但在接收数据库中存储为“123 example road”。这并不是一直都会发生,所以我对可能的原因感到困惑

有没有人经历过这样的问题?感谢您的帮助

这就是cURL代码的样子:

//create array of data to be posted

foreach( $registrationfields as $field ) {

if( $field->name == 'email') $field->name = 'user_email';

if( $field->name == 'delimiter_sendregistration') continue;

if( $field->type == 'captcha') continue;

if( $field->type == 'delimiter') continue;



switch($field->name) {

    case 'country':

        require_once(CLASSPATH.'ps_country.php');

        $country = new ps_country();

        $dbc = $country->get_country_by_code($dbbt->f($field->name));

        if( $dbc !== false ) $val = $dbc->f('country_name');

        break;

    default: 

        $val = $dbbt->f($field->name);

        break;

}



$post_data[$field->name] = $val;



} 

$post_data['order_id'] = $order_id;

$post_data['order_date'] = $order_date;

$post_data['order_status'] = $order_status;



$post_data['username'] = $username;



//traverse array and prepare data for posting (key1=value1)

foreach ( $post_data as $key => $value) {

    $post_items[] = $key . '=' . $value;

}



//create the final string to be posted using implode()

$post_string = implode ('&', $post_items);



//create cURL connection

$curl_connection = 

  curl_init('http://--url-here');



//set options

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);

curl_setopt($curl_connection, CURLOPT_USERAGENT, 

  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);

curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);



//set data to be posted

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);



//perform our request

$result = curl_exec($curl_connection);



//show information regarding the request

print_r(curl_getinfo($curl_connection));

echo curl_errno($curl_connection) . '-' . 

                curl_error($curl_connection);



//close the connection

curl_close($curl_connection);

尝试使用
base64
发送编码为一个参数的数据。不要使用本机
php
函数,因为它们可能会输出特殊字符,如斜杠。使用第一个答案中列出的功能

我认为问题在于
curl
如何编码空间(%20)以及目标脚本如何读取它们

示例(使用链接中的函数):


在我重新分析代码后,这个问题得到了解决。而不是使用循环和“内爆”来修改数组以形成类似字符串的形式:

//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
  $post_items[] = $key . '=' . $value;
}

//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
我改用了“”函数,它可以完成相同的任务,而不会导致错误

$post_string = http_build_query($post_data) . "\n";

有趣的是,这些空间只有在某些时候才能被正确地编码/解码。我来看看这是怎么回事-谢谢!我承认我不太了解不同情况下的字符串编码问题,但我见过很多次开发人员在以url参数发送文本时,试图避免空格。有时是base64,有时他们将空格改为“+”符号(如果他们确定“+”不会以任何其他方式使用)。
$post_string = http_build_query($post_data) . "\n";