简体   繁体   中英

PHP Codeigniter - Passed urlencode in function removes .html in url

The value is correct in the 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){
$urlDecoded = urldecode($url);

I have tried to echo out both encoded and decoded values, but the.html is still missing.

Since I use page suffix.html as default in codeigniter, it seems it reads this as not part of the passed variable.

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.

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) .

So in application/helpers/my_helper.php add

<?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:

$autoload['helper'] = array('my_helper');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM