简体   繁体   中英

Codeigniter current_url avoid jpg etc

I'm quite new in codeigniter. I'm using the current_url() function to preserve previously viewed page's URL. But the function (I think from different ajax calls) gives ie jpg files' url.

Like this:

/uploads/default/files/HTC.jpg

I'd like to avoid these and just preserve those URLs which are used in Browser's URL bar.

Any idea? Thanks in advance!

I assume you are using current_url() and then saving the output of this function somewhere for later retrieval.

So you could, before you save the string, perform a regex check to see if it fits the format you want:

$pattern = '~.+\.[a-zA-Z]{0,3}$~';
$string = current_url();

preg_match($pattern, $string, $matches);

if (empty($matches)) {
    // We can save the url
}

The regex will hit on Urls which end in a . with zero to 3 letters:

  • HTC.jpg will fail
  • la/di.php will fail
  • la/items/2 will pass

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