Php URL空间替换添加到URL的cauese 20
我的Php URL空间替换添加到URL的cauese 20,php,codeigniter,url,preg-replace,space,Php,Codeigniter,Url,Preg Replace,Space,我的codeigniter控制器名称类似于asd-asd-Aldsds-98Hsds。我需要用-符号替换空格。为此我写了 $news_title = $this->uri->segment(1); $news_title = strtolower($news_title); $url = preg_replace("![^a-z0-9]+!i", "-", $news_title); 但是上面这一行输出的$url如下: asd%20asd%20ALDSD%209
codeigniter
控制器名称类似于asd-asd-Aldsds-98Hsds
。我需要用-
符号替换空格。为此我写了
$news_title = $this->uri->segment(1);
$news_title = strtolower($news_title);
$url = preg_replace("![^a-z0-9]+!i", "-", $news_title);
但是上面这一行输出的$url
如下:
asd%20asd%20ALDSD%2098HSD
如何从我的url中删除这些
%20
。任何这些出现的原因?看起来像…->uri->。。。将执行URL编码。URL不能有空格。如果无法避免,则需要将它们转换为%20以使url有效。看起来像…->uri->。。。将执行URL编码。URL不能有空格。如果无法避免,则需要将它们转换为%20以使url有效。在preg\u替换之前使用
$news_title = urldecode($news_title);
在更换前使用
$news_title = urldecode($news_title);
谢谢M42。它能用。我想它应该是
urldecode
而不是url\u decode
。@Nitish:是的,你说得对。更正。谢谢M42。它能工作。我想它应该是urldecode
而不是url\u decode
。@Nitish:是的,你说得对。更正。感谢CrayThanks的解释Cray