WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] problem with UTF-8 in xmlrpc_encode_request (2 posts)

  1. SamiBH
    Member
    Posted 2 years ago #

    Hello,

    I'm using the XML-RPC to add posts,and it's works great But characters not correct (utf-8)

    I'm using this code:

    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'=>1,  // 1 to allow comments
            'mt_allow_pings'=>1,  // 1 to allow trackbacks
            'post_type'=>'post',
            'mt_keywords'=>$keywords,
    		/*'_aioseop_keywords'=>"keyword",
    		'aioseop_title'=>"title",
    		'_aioseop_title'=>"title",
    		'_aioseop_description'=>"description",*/
    		"custom_fields" => array(
    array( 'key' => 'try', 'value' => 'these are keywords' ),
    array( 'key' => '_test', 'value' => 'this is the title' )
    		),
            'categories'=>array($category)
        );
        $params = array(0,$username,$password,$content,true);
        $request = xmlrpc_encode_request('metaWeblog.newPost',$params);
        $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;

    utf-8 not working in the code.

    if anyone can help, I will be grateful

    thank you,

  2. SamiBH
    Member
    Posted 2 years ago #

    fixed :)

    thanks to

    http://wordpress.org/support/topic/xml-rpc-turkish-character-problem?replies=9

    and

    http://thr.gen.tr/php/xmlrpc-turkce-karakter-sorunu.html

    just change

    $request = xmlrpc_encode_request('metaWeblog.newPost',$params);

    to

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags