Created
August 6, 2018 17:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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