0
我已经创建了一个脚本来删除特定个人的所有用户属性。我能够使用api调用从xml获取用户的属性。我正在使用删除api来删除每个属性。测试什么时候没有属性
我希望能够测试什么时候没有更多的属性,然后相应地输出一条消息。在for循环中找到每个属性的位置。任何帮助肯定是赞赏的。
下面是代码:
<?php
$user_id="[email protected]";
$url=('http://user:[email protected]/@api/users/[email protected]/properties');
$xmlString=file_get_contents($url);
$delete = "http://user:[email protected]/@api/DELETE:users/$user_id/properties/%s";
$xml = new SimpleXMLElement($xmlString);
function curl_fetch($url,$username,$password,$method='DELETE')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // returns output as a string instead of echoing it
curl_setopt($ch,CURLOPT_USERPWD,"$username:$password"); // if your server requires basic auth do this
return curl_exec($ch);
}
foreach($xml->property as $property) {
$name = $property['name']; // the name is stored in the attribute
curl_fetch(sprintf($delete, $name),'user','12345');
}
?>
感谢,我想这就是我需要的 – Aaron 2010-10-13 14:37:33