如果我想使用变量创建URL,我有两个选择来编码字符串.urlencode()和rawurlencode().
究竟有什么区别,哪个是首选?
所以我试图卷曲这个网址:
http://images.fastcompany.com/upload/Screen shot 2011-04-28 at 8.13.21 PM.png
URL编码它读作:
http%3A%2F%2Fimages.fastcompany.com%2Fupload%2FScreen+shot+2011-04-28+at+8.13.21+PM.png
但是,curl显然需要将其解码为正确的URL.
我该如何解决这个问题?一旦到达任何空格,cURL就会掉落其余的字符串...... :(
我应该提到我不能用双引号包装URL,因为它是一个被发布的变量.
编辑:hahahahaha wowwwwww brainfart ..谢谢你们:P
我正在执行以下命令:
<?php
copy ("http://localhost/.../DSCF8253.JPG" , "sites/default/files/DSCF8253.JPG"); // Success!
copy ("http://localhost/.../DSCF8260.JPG" , "sites/default/files/DSCF8260.JPG"); // Success!
copy ("http://localhost/.../HERMAN 085.jpg" , "sites/default/files/HERMAN 085.jpg" ); // Fail!
?>
Run Code Online (Sandbox Code Playgroud)
前两个复制正常,但不是最后一个.为什么?
它必须与文件名有关(最后一个在085之前有一个空格).
任何帮助将不胜感激!
我试图调用一个基本上看起来像这样的Web服务:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'
Run Code Online (Sandbox Code Playgroud)
这就是我称之为Web服务的方式:
$endpoint = "http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'";
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'Content-type: application/xml'
)
);
$context = stream_context_create( $opts );
$result = file_get_contents( $endpoint, false, $context );
$xml_result = simplexml_load_string( $result );
echo $xml_result->success;
Run Code Online (Sandbox Code Playgroud)
所以在这里,我什么都没有,xml_result是空的.这是有趣的部分 - 当我从描述中删除空格时:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Somedescription'
Run Code Online (Sandbox Code Playgroud)
一切都很好,我从网络服务得到答案.还尝试使用chrome rest客户端调用Web服务和描述中的空白区域,一切正常,我有回复.所以这导致我在这里使用Web服务中的空格来处理某种PHP问题.请帮忙 !
更新:
print_r($result)
Run Code Online (Sandbox Code Playgroud)
结果是
1
Run Code Online (Sandbox Code Playgroud) php ×4
copy ×1
curl ×1
email ×1
html ×1
mailto ×1
parsing ×1
url-encoding ×1
urlencode ×1
web-services ×1