Skip to content

Instantly share code, notes, and snippets.

@farinspace
Created August 6, 2018 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farinspace/30e8d006717d60809cada28aa516d738 to your computer and use it in GitHub Desktop.
Save farinspace/30e8d006717d60809cada28aa516d738 to your computer and use it in GitHub Desktop.
Trim non alpha-numeric characters from the beginning and end of a string
<?php
function trim_non_alphanum( $str ) {
$str = preg_replace( '/^[^[:alnum:]]+/u', '', $str ); // beginning
return preg_replace( '/[^[:alnum:]]+$/u', '', $str ); // end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment