删除php中url的一部分


Removing a part of url in php

我想从url中删除%+ascii codes

示例:

来自

 http://prexprint.com/Laminated%20Business%20Cards

 http://prexprint.com/Laminated Business Cards

浏览器将始终在URL spaces中渲染%20,我们无法更改它。

如果你想将其更改为http://prexprint.com/Laminated Business Cards,而不是这样做,请将你的url设置为

http://prexprint.com/Laminated+Business+Cards

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-Business-Cards.即使您放置这样的链接http://prexprint.com/Laminated Business Cards,浏览器也会自动将空格替换为"%20"

JS:

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

编辑:

var orgUrl = 'http://prexprint.com/Laminated%20Business%20Cards';
var reqUrl = decodeURI(orgUrl)
reqUrl = reqUrl.replace(/' /g, '-');
console.log(reqUrl)
window.location.href = reqUrl

使用PHP 的urldecode函数

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

您可以使用

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

您应该对url进行编码,以解决兼容性问题。

"如果它没有坏,就不要修复它。"