Advertisement
petschko

mb_basedir() multibyte function

Jul 28th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Author: Peter Dragicevic [peter-91@hotmail.de]
  4.  * Authors-Website: http://petschko.org/
  5.  * Licence: http://creativecommons.org/licenses/by-sa/4.0/
  6.  * Date: 28.07.2015
  7.  * Time: 10:34
  8.  */
  9.  
  10. if(!function_exists("mb_basename")) {
  11.     /**
  12.      * @param string $path - Path to convert
  13.      * @param null $suffix - Remove this ending if exists
  14.      * @return string - Filename without path (and may without suffix)
  15.      */
  16.     function mb_basename($path, $suffix = null) {
  17.         if(mb_stripos($path, DIRECTORY_SEPARATOR) !== false)
  18.             $basename = mb_substr($path, mb_strripos($path, DIRECTORY_SEPARATOR));
  19.         else
  20.             $basename = $path;
  21.  
  22.         if($suffix && mb_stripos($basename, $suffix)) {
  23.             $suffix_pos = mb_strlen($suffix) * -1;
  24.             $base_end = mb_substr($basename, $suffix_pos);
  25.  
  26.             if($base_end == $suffix)
  27.                 $basename = mb_substr($basename, 0, $suffix_pos);
  28.         }
  29.  
  30.         return $basename;
  31.     }
  32. }
  33.  
  34. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement