Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP ereg_replace allow spaces

using preg_replace I want to allow only alphanumeric and spaces, but ereg_replace("[^A-Za-z0-9\w\] deletes all spaces.

What could I do in order to fix it?

Thanks in advance

like image 344
Itamar Avatar asked Dec 27 '22 19:12

Itamar


1 Answers

you forgot a space

[^A-Za-z0-9\w\ ]
______________^

eg:

$returnValue = preg_replace('@[^A-Za-z0-9\w\ ]@', '', 'I forgot a %space!!!');
// I forgot a space
like image 188
Mihai Iorga Avatar answered Jan 12 '23 07:01

Mihai Iorga