Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php URL空间替换添加到URL的cauese 20_Php_Codeigniter_Url_Preg Replace_Space - Fatal编程技术网

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