开发者

How to encode only 2 chars in path?

I have a $delete path and a $user_id each include '#' and '@' respectively within the string. How can I replace each with the encoded value %23 and $40.

I tired using str_replace but did not have any luck: str_replace($string, array('@', '#'), array('%40', '%23'));

My full Delete path looks like this:

$delete = "http://admin:12345@192.168.245.133/@api/deki/DELETE:users/$user_id/properties/%s";

I feel like the $user_id should be pretty simple. For the properties it has to loop through to get all the available properties. You can see the loop below:

foreach($xml->property as $property) {
      $name = $property['name']; // the name is stored in the attribute
      curl_fetch(sprintf($delete, $name),'admin','12345');
    }

Each property contains a '#', so is t开发者_如何学Gohere a way that each iteration which modify '#' to be the appropriate value?

Thanks in advance.


You use str_replace wrongly: The first parameter is search, the second replace and the third subject:

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

So:

str_replace(array('@', '#'), array('%40', '%23'), $string)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜