![](/img/trans.png)
[英]php urlencode and htmlspecialchars a variable inside started function within html <a href>
[英]PHP Codeigniter - Passed urlencode in function removes .html in url
URl 中的值是正确的:/optimization/page/%2Flove-your-body-club.html
但是当我在 function 的给定变量中收集 url 时,删除了.html。
function($url){
$urlDecoded = urldecode($url);
我试图回显编码和解码的值,但仍然缺少.html。
由于我在 codeigniter 中默认使用页面 suffix.html 作为默认值,因此它似乎将其读取为不是传递变量的一部分。
有什么解决方法吗?
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.
尝试这个:
function($url) {
$urlDecoded = urldecode($url . $this->config->item('url_suffix'));
}
我可能会创建一个助手 function ,您可以在应用程序的任何地方调用它,也许称之为myurldecode($url)
。
所以在application/helpers/my_helper.php
添加
<?php
function myurldecode($url) {
$CI =& get_instance();
return urldecode($url . $CI->config->item('url_suffix'))
}
在application/config/autoload.php
添加我们的新帮助文件,以便它在任何地方都可用:
$autoload['helper'] = array('my_helper');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.