Recently I played with php xml rpc library. My main goal is to post articles from php to wordpress blog.
There are a lot of implementation on the web.
First I tried the one on sourceforge.
http://phpxmlrpc.sourceforge.net/
I use the library to develop method to post a new articles or edit an existing article on a wordpress blog.
The sample code is like this:
$content['title'] = ”A post”
$content['description'] = $article;
$content['categories'] = “General”;
$c = new xmlrpc_client(“/xmlrpc.php”, “localhost”, 80);
$x = new xmlrpcmsg(“metaWeblog.newPost”,
array(php_xmlrpc_encode(“1″),
php_xmlrpc_encode($blogUser),
php_xmlrpc_encode($blogPass),
php_xmlrpc_encode($content),
php_xmlrpc_encode(“1″)));
$c->return_type = ‘phpvals’;
$r =$c->send($x);
if ($r->errno==”0″)
{
echo “Successfully Posted! articel ID:”;
print $r->val;
}
else
{
echo “xmlrpc meets some error”;
print_r($r);
}
But when I tried to implement uploading images with metaWeblog.newMediaObject method, the library cannot support base64 value encoding correctly.
Then I realized the library used by wordpress itself should be a good candidate. It is actually from here: http://scripts.incutio.com/xmlrpc/beginners.php
$client = new IXR_Client(‘http://scripts.incutio.com/xmlrpc/simpleserver.php’);
if (!$client->query(‘test.getTime’)) {
die(‘An error occurred – ‘.$client->getErrorCode().”:”.$client->getErrorMessage());
}
print $client->getResponse();
This library is more easily to use. Highly recommended!