PHP function chopOffLastDir()

| | | | | |

I wrote this funtion to help avoid 404 errors when a user asks for something like /my/site/section/doesntexist/. I use it to help bump users “up” to /my/site/section/. Feel free to use/modify/share it; I'm making it public domain.

[coolcode lang="php" download="chopOffLastDir.php"] [/coolcode]

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
alanhogan's picture

Note

I would like to point out the basename() function of PHP has a similar purpose. However this one may be useful for very simple CMSs.

Alan J. Hogan

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Page Outdated! Comments disabled!

As do many people using Drupal to power their website, I get a lot of comment spam, and Drupal's spam filter is horrible! So I have permanently disabled comments on old.alanhogan.com. Try the new version of this page (which may not exist, but should if this page actually has content besides a list of other articles).

Consider using my contact form to get in touch. And remember that AlanHogan.com is live and old.alanhogan.com is here as a backup only, and a stopgap measure because some AlanHogan.com functionality is not implemented yet.