How to trim multiple characters at begin and end of string.
string should be something like {Hello {W}orld}
.
i want to trim both {
and }
at begin and end.
don't want to use multiple trim
function.
How to trim multiple characters at begin and end of string.
string should be something like {Hello {W}orld}
.
i want to trim both {
and }
at begin and end.
don't want to use multiple trim
function.
Use the optional second argument to trim
which allows you to specify the list of characters to trim:
<?php
$str = "{Hello {W}orld}";
$str = trim($str, "{}");
echo "Trimmed: $str";
Output:
Trimmed: Hello {W}orld
Is there always a character at the beginning and at the end, that you want to remove? If so you could just use the following:
<?php
$string = '{Hello {W}orld}';
echo substr( $string, 1, strlen( $string )-2 );
?>