Trim multiple characters using php

前端 未结 2 1626
执笔经年
执笔经年 2021-02-12 17:28

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 }<

相关标签:
2条回答
  • 2021-02-12 18:16

    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 );
    ?>
    

    See: http://codepad.org/IDbG6Km2

    0 讨论(0)
  • 2021-02-12 18:24
    $str = "{Hello {W}orld}";
    $str = trim($str, "{}");
    
    echo "Trimmed: $str";
    
    0 讨论(0)
提交回复
热议问题