Skip to content

Instantly share code, notes, and snippets.

@farinspace
Created August 6, 2018 17:28
Show Gist options
  • 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