删除php中url的一部分

删除php中url的一部分,php,Php,我想从url中删除%,+,ascii代码 例如: 从 到 PHP函数的使用 <?php echo urldecode('http://prexprint.com/Laminated%20Business%20Cards'); ?> 您可以使用 <?php echo urldecode('http://prexprint.com/Laminated%20Business%20Cards'); ?> JS就在这里: var orgUrl = 'http://prexp

我想从
url
中删除
%
+
ascii代码

例如:

PHP函数的使用

<?php
echo urldecode('http://prexprint.com/Laminated%20Business%20Cards');
?>

您可以使用

<?php echo urldecode('http://prexprint.com/Laminated%20Business%20Cards'); ?>

JS就在这里:

var orgUrl = 'http://prexprint.com/Laminated%20Business%20Cards';
var reqUrl = decodeURI(orgUrl);
console.log(reqUrl);
编辑:


浏览器将始终在
URL
空间中呈现
%20
,我们无法更改它

如果您想更改它
http://prexprint.com/Laminated 名片
,而不是用它来创建您的url

http://prexprint.com/Laminated+商务+卡

http://prexprint.com/LaminatedBusinessCards

$x = 'http://prexprint.com/Laminated%20Business%20Cards';
$y =str_replace('%20',' ',$x);
echo $y;
或使用

<?php echo rawurldecode('http://prexprint.com/Laminated%20Business%20Cards');  ?>


地址栏中的URL不能带有空格。您可以使用URL重写,使您的URL看起来像这样。即使您放置这样的链接
http://prexprint.com/Laminated 名片
,浏览器将自动将空格替换为“%20”

为了兼容性问题,您应该对URL进行编码



“如果它没有坏,就不要修理它。”

plz分享自己对这个问题的评论您是否尝试过使用unescape?将
%20
替换为
-
。我正在使用unescape..但我是hv'nt解决方案..所以请发送另一个关于这个问题的逻辑Mathanks shankar…但是我是hv'nt解决方案,因为urlencode不会删除chrome中url栏上的%20…所以请在您访问google chrome时,请检查一下表示url
http://prexprint.com/Laminated 名片
在地址中,它会自动将
%20
添加到空格中,同样,如果URL是这样的
http://prexprint.com/Laminated 名片#12663
它将取代#as
%23
。层压名片#12663。。?请使用elabrote.。@TbsAmit,#是一个符号,因此它将自动编码为%23。确定。。现在,您可以用#…给出一个表达式,但我只想在url栏中使用+或-…?$x='';//$x=str_替换(“,“+”,$title1);//珠三角($x);我使用这种类型的逻辑$x='';//$x=str_替换(“,“+”,$title1);//珠三角($x);但在谷歌浏览器中,chrome不会删除%20。所以请检查谷歌浏览器。谢谢浏览器将始终在URL空间中显示%20。我们无法更改它。Tushar Plz explain…?@TusharGupta在此处查看我的评论>我使用的是decodeURl,但在google chrome上。现在在url栏中显示%20,因此请登录google chrome…请在chrome的开发人员控制台中尝试上述代码时表示感谢,它给了我这个输出-名片这个输出prexprint.com/层压名片显示在google chrome的url栏上..?chrome地址栏??你能在你的问题中详细说明你到底想做什么吗?好的……我想从谷歌chrome浏览器的url栏上的层压%20商业%20卡片中删除%20。我想看起来像url栏上的层压名片。你的url解码在这个问题上不起作用……所以请检查谷歌chrome上的%20没有从url栏上删除最奇怪的事情发生了。我打开了
http://prexprint.com/Laminated 名片
在我的浏览器(FF v22)中,它显示了
%20
,其中空格为每秒1/2,然后显示
http://prexprint.com/Laminated 名片
完全如我的地址栏所示;奇怪的可能是因为我的浏览器版本?我无法解释。请举一个例子…?@Fred:我很惊讶O@user2636734:这个问题的URl是一个更好的例子。@SuryaS我也是。我的猜测是,这是因为我的web浏览器版本或服务器本身的配置。这只能是其中一个原因。
var orgUrl = 'http://prexprint.com/Laminated%20Business%20Cards';
var reqUrl = decodeURI(orgUrl)
reqUrl = reqUrl.replace(/\ /g, '-');
console.log(reqUrl)
window.location.href = reqUrl
$x = 'http://prexprint.com/Laminated%20Business%20Cards';
$y =str_replace('%20',' ',$x);
echo $y;
<?php echo rawurldecode('http://prexprint.com/Laminated%20Business%20Cards');  ?>