Get only words from A-z and numbers 0-9

1

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

    
asked by anonymous 31.12.2014 / 14:43

2 answers

1

Just use str_replace() .

$chars = array('!', '@', '#');
echo str_replace($chars, '', 'oh! texto com # e @ para apagar!');

See working on ideone .

    
31.12.2014 / 14:57
1

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);

Ideone

    
31.12.2014 / 16:12