本文介绍了PHP urlencode-仅编码文件名,请勿触摸斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip
urlencode($myurl);

问题在于,urlencode也将对斜杠进行编码,从而使URL无法使用.我如何只编码最后一个文件名?

The problem is that urlencode will also encode the slashes which makes the URL unusable. How can i encode just the last filename ?

推荐答案

尝试一下:

$str = 'http://www.example.com/some_folder/some file [that] needs "to" be (encoded).zip';
$pos = strrpos($str, '/') + 1;
$result = substr($str, 0, $pos) . urlencode(substr($str, $pos));

您正在寻找最后一个斜杠符号.之前的部分还可以,所以只需复制一下即可.然后urlencode其余.

You're looking for the last occurrence of the slash sign. The part before it is ok so just copy that. And urlencode the rest.

这篇关于PHP urlencode-仅编码文件名,请勿触摸斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 04:37