How can I remove leading and trailing non-alphanumeric characters

后端 未结 2 1682

I\'m looking to \"trim\" non-alphanumerics from a string, similar to how trim() works with whitespace.

Help me convert #str|ng# to st

2条回答
  •  时光说笑
    2020-12-07 05:57

    You don't need regex, use trim() and specify what to trim (it trims whitespace by default):

    $string = trim($string, "#");
    

    Docs: http://php.net/trim

提交回复
热议问题