string operations
i'm creating a functions that will remove and add brackets at the beginning and end of the string. what is the best function to remove the character from a string. i was thinking about using ltrim() and rtrim OR str_replace()... which is more efficient? (see code below):
<?
function remove_brackets($element) {
$last_char = strlen($element) - 1;
if(strpos($element,"{") == 0 && strpos($element,"}") == $last_char) {
$element = ltrim($element,"{");
$element = rtrim($element,"}");
return $element; }
}
$string = "1,{2:4:5},2,{6:8:10},3,{11:14}";
$string = split(",",$string);
echo remove_brackets($string[1]);
?>
thanx in advance :D:D
the genuine genius
__________________
www.campusgrind.com - college portal
|