Last active
March 14, 2021 11:57
-
-
Save Ambalus/60253115b3ba0e6e3638 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if(!function_exists('mb_ucfirst')) { | |
function mb_ucfirst($str, $enc = 'UTF-8') { | |
return Wader\Mbstring::ucfirst($str, $enc); | |
} | |
} | |
if(!function_exists('mb_lcfirst')) { | |
function mb_lcfirst($str, $enc = 'UTF-8') { | |
return Wader\Mbstring::lcfirst($str, $enc); | |
} | |
} | |
if(!function_exists('mb_str_replace')){ | |
function mb_str_replace($search, $replace, $subject, &$count = 0){ | |
return Wader\Mbstring::str_replace($search, $replace, $subject,$count); | |
} | |
} | |
if(!function_exists('mb_ucwords')){ | |
function mb_ucwords($word){ | |
return Wader\Mbstring::ucwords($word); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Wader; | |
final class Mbstring { | |
/** | |
* upcase first char in string | |
* @param string $str | |
* @return string | |
*/ | |
public static function ucfirst($string, $enc = 'UTF-8'){ | |
return mb_convert_case(mb_substr($string,0,1), MB_CASE_UPPER, $enc). | |
mb_substr($string, 1, mb_strlen($string, $enc), $enc); | |
} | |
/** | |
* lowcase first char in string | |
* @param string $str | |
* @return string | |
*/ | |
public static function lcfirst($string, $enc = 'UTF-8'){ | |
return mb_convert_case(mb_substr($string,0,1), MB_CASE_LOWER, $enc). | |
mb_substr($string, 1, mb_strlen($string, $enc), $enc); | |
} | |
public static function ucwords($word){ | |
return mb_convert_case($word,MB_CASE_TITLE); | |
} | |
public static function str_replace($search, $replace, $subject, &$count = 0){ | |
if (!is_array($subject)){ | |
$searches = is_array($search) ? array_values($search) : array($search); | |
$replacements = is_array($replace) ? array_values($replace) : array($replace); | |
$replacements = array_pad($replacements, count($searches), ''); | |
foreach ($searches as $key => $search){ | |
$parts = mb_split(preg_quote($search), $subject); | |
$count += count($parts) - 1; | |
$subject = implode($replacements[$key], $parts); | |
} | |
}else{ | |
foreach ($subject as $key => $value){ | |
$subject[$key] = self::str_replace($search, $replace, $value, $count); | |
} | |
} | |
return $subject; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment