Only get words from A-z and numbers 0-9

Asked

Viewed 1,472 times

1

How can I remove anything other than a letter and number string, that is to remove (!@#$%^&*():"><?} etc.) and keep only the letters of a-z and numbers of 0-9

  • You can use several str_replace cascades by substituting "" (empty string). or regular expressions (never tested)

  • 1

    Can any of the answers be accepted here?

2 answers

1

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.