2012-03-17 101 views
1

我想通过xml-rpc发布到我的WordPress网站。PHP:xml-rpc和土耳其字符

我对土耳其人有两个问题。

1 - 当我使用其中一个字符(Çç,Ğğ,Iı,Öö,Şş,Üü)在标题中发送一个帖子给wordpress没有标题。

2 - 当我使用形式相同的字符在身体内容它发送不同的形式。

例如在正文内容我有 “Ankaralıyım” 一个DIT进行到WordPress作为 “Ankaralýyým”。

这里是我的代码使用

<?php 
$title="Karaçay"; 
$body="Ankaralıyım"; 

$rpcurl="http://localhost/wp/xmlrpc.php"; 
$username="admin"; 
$password="pass"; 
$categories="try"; 

echo wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$categories,''); 

function wpPostXMLRPC($title,$body,$rpcurl,$username,$password,$category,$keywords='',$encoding='UTF-8') 
{ 
    $title = htmlentities($title,ENT_NOQUOTES,$encoding); 
    $keywords = htmlentities($keywords,ENT_NOQUOTES,$encoding); 

    $content = array(
     'title'=>$title, 
     'description'=>$body, 
     'mt_allow_comments'=>0, // 1 to allow comments 
     'mt_allow_pings'=>0, // 1 to allow trackbacks 
     'post_type'=>'post', 
     'mt_keywords'=>$keywords, 
     'categories'=>array($category) 
    ); 
    $params = array(0,$username,$password,$content,true); 
    $request = xmlrpc_encode_request('metaWeblog.newPost',$params, array('encoding'=>'UTF-8')); 
    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
    curl_setopt($ch, CURLOPT_URL, $rpcurl); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 1); 
    $results = curl_exec($ch); 
    curl_close($ch); 
    return $results; 
} 

?> 

我没有任何语言问题,当我从WordPress的加职位。

我该如何解决这个问题?

,我已经尝试了不同的代码同样的事情,这时候如果有一个在标题或交任何土耳其字符,同时创建一个新的职位,32700我得到这个结果 错误:解析错误。不能很好地形成 二码为

<?php 
     require("class-IXR.php"); 
     $client = new IXR_Client('http://localhost/wp/xmlrpc.php'); 

     $USER = 'admin'; 
     $PASS = 'pass'; 

     $content['title'] = 'Test title '.mt_rand(); 
     $content['categories'] = array("NewCategory","Nothing"); 
     $content['description'] = '<p>Lorem ırmak ipsum dolor sit amet</p>'; 
     $content['custom_fields'] = array(array('key' => 'my_custom_fied','value'=>'yes')); 
     $content['mt_keywords'] = array('foo','bar'); 

     if (!$client->query('metaWeblog.newPost','', $USER,$PASS, $content, true)) 
     { 
      die('Error while creating a new post' . $client->getErrorCode() ." : ". $client->getErrorMessage()); 
     } 
     $ID = $client->getResponse(); 

     if($ID) 
     { 
      echo 'Post published with ID:#'.$ID; 
     } 

?> 

这是两种不同的方式,通过XML-RPC送岗位到WordPress。但不同于英语的行为不起作用。我所知道的是xml-rpc支持utf-8。

回答

0

您应该添加escaping->markup参数xmlrpc_encode_request

xmlrpc_encode_request('blogger.newPost',$params, 
          array('encoding'=>'UTF-8','escaping'=>'markup')); 
0

这肯定看起来像管道的某些部分不理解或履行要使用UTF-8的数据。

您是否尝试过检查被发送到服务器的原始数据,无论是通过像tcpdumpnetcatwireshark工具

您也可以尝试启用调试的卷曲,使用选项CURLOPT_VERBOSECURLOPT_HEADER

curl_setopt($ch,CURLOPT_VERBOSE,1) 
curl_setopt($ch,CURLOPT_HEADER,1) 
+0

尝试将“CURLOPT_HEADER”行退出,似乎在后面的某个步骤中将解析混淆。 – 2012-03-17 07:13:38

+0

我已经尝试了您的代码的正确版本,但仍然有同样的错误。有些字母很好,但是Iı,Şş,Ğğ仍然没有工作。 – 2012-03-17 15:06:08