有没有办法对路径中的目录分隔符/进行 urlencode ?
喜欢
urlencode('/this/is/my/file right here.jpg');
最佳答案
你可以使用
-
explode
将您的路径分成路径段, -
array_map
申请rawurlencode
在每个项目上(不要使用urlencode
,这只适用于 application/x-www-form-urlencoded encoded 查询参数!),并且 -
implode
将片段重新组合在一起。
所以全部放在一行中:
$path = implode('/', array_map('rawurlencode', explode('/', $path)));
关于php - urlencode 除外/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2834524/