How can I remove anything other than the letter and number of a string , that is, remove ( !@#$%^&*():"><?}
etc.) and keep only az letters and numbers 0-9
How can I remove anything other than the letter and number of a string , that is, remove ( !@#$%^&*():"><?}
etc.) and keep only az letters and numbers 0-9
Just use str_replace()
.
$chars = array('!', '@', '#');
echo str_replace($chars, '', 'oh! texto com # e @ para apagar!');
See working on ideone .
Using the following regular expression:
[^\w]
And make the substitution using preg_replace
:
$texto = 'Ex#em$!plo uti@!lizando r3gex';
echo preg_replace('/[^\w]/', '', $texto);