[英]PHP Codeigniter - Passed urlencode in function removes .html in url
The value is correct in the URl: /optimization/page/%2Flove-your-body-club.html URl 中的值是正确的:/optimization/page/%2Flove-your-body-club.html
But when I collect the url in the given variable in the function, the.html is removed.但是当我在 function 的给定变量中收集 url 时,删除了.html。
function($url){
$urlDecoded = urldecode($url);
I have tried to echo out both encoded and decoded values, but the.html is still missing.我试图回显编码和解码的值,但仍然缺少.html。
Since I use page suffix.html as default in codeigniter, it seems it reads this as not part of the passed variable.由于我在 codeigniter 中默认使用页面 suffix.html 作为默认值,因此它似乎将其读取为不是传递变量的一部分。
Any workaround to this?有什么解决方法吗?
Assuming you have the url_suffix
configuration set to .html
in application/config/config.php
, you could just modify your function to always append the url_suffix
to the input string. Assuming you have the
url_suffix
configuration set to .html
in application/config/config.php
, you could just modify your function to always append the url_suffix
to the input string.
Try this:尝试这个:
function($url) {
$urlDecoded = urldecode($url . $this->config->item('url_suffix'));
}
I'd probably create a helper function that you can call everywhere in your app, maybe call it myurldecode($url)
.我可能会创建一个助手 function ,您可以在应用程序的任何地方调用它,也许称之为
myurldecode($url)
。
So in application/helpers/my_helper.php
add所以在
application/helpers/my_helper.php
添加
<?php
function myurldecode($url) {
$CI =& get_instance();
return urldecode($url . $CI->config->item('url_suffix'))
}
And in application/config/autoload.php
add our new helper file so that it's available everywhere:在
application/config/autoload.php
添加我们的新帮助文件,以便它在任何地方都可用:
$autoload['helper'] = array('my_helper');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.