我只需要编码$ delete路径的一部分。只有电子邮件地址中的@和属性中的#。我知道如何使用urlencode来完成整个过程,但不仅仅是这样。它的工作方式是循环获取属性,其中大部分包含名称中的#。任何能够帮助修改以使其有效的人都将非常感激!
删除:
$delete = "http://admin:12345@192.168.245.133/@api/deki/DELETE:users/$user_id/properties/%s";
以下是目前的代码:
<?php
$user_id="john_smith@ourwiki.com";
$url=('http://admin:12345@192.168.245.133/@api/deki/users/=john_smith@ourwiki.com/properties');
$xmlString=file_get_contents($url);
$delete = "http://admin:12345@192.168.245.133/@api/deki/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),'admin','12345');
}
?>
答案 0 :(得分:0)
urlencode函数不允许您将其限制为字符子集。