Search code examples
phptrim

Remove a specified character from the start and end of a string


How to get string by trimming * at start (if present) and end (if present) of given string using RegExp in PHP?


Solution

  • Are you sure you need regex? PHP's trim() function allows you to specify a character list to trim from either side:

    $stripAsterisks = trim($string, '*');
    

    http://php.net/trim