Last active
August 29, 2015 14:19
-
-
Save rafasashi/c918b48c15a0b333fb8d to your computer and use it in GitHub Desktop.
This file contains 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
function custom_trim($str,$trim=''){ | |
if($trim==''){ | |
$str=trim($str); | |
} | |
if($trim==' '){ | |
$str=preg_replace('/^\p{Z}+|\p{Z}+$/u', '', $str); | |
} | |
else{ | |
$str=custom_ltrim($str,$trim); | |
$str=custom_rtrim($str,$trim); | |
} | |
return $str; | |
} | |
function custom_ltrim($str,$trim){ | |
if(is_array($trim)){ | |
foreach($trim as $t){ | |
$str=custom_rtrim($str,$t); | |
} | |
} | |
else{ | |
if(custom_strlen($trim)==1){ | |
$str=ltrim($str,$trim); | |
} | |
else{ | |
$delim="`"; | |
//$patern="(".$trim.")(.*)"; | |
$patern="^(".$trim.")?(.*)$"; | |
$str=preg_replace($delim.$patern.$delim."i", "$2", $str); | |
} | |
} | |
return $str; | |
} | |
function custom_rtrim($str,$trim){ | |
if(is_array($trim)){ | |
foreach($trim as $t){ | |
$str=custom_rtrim($str,$t); | |
} | |
} | |
else{ | |
if(custom_strlen($trim)==1){ | |
$str=rtrim($str,$trim); | |
} | |
else{ | |
$delim="`"; | |
//$patern="(".$trim.")(.*)"; | |
$patern="^(.*)".$trim."$"; | |
$str=preg_replace($delim.$patern.$delim."i", "$1", $str); | |
} | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment