If you don't want to get rid of ,
s, you can add them to your group in the square brackets:
preg_replace("/[^, \w]+/", '',($_POST['keywords']))
Вопрос
This is my code
$keywords = mysql_escape_string(preg_replace("/[^ \w]+/", '',($_POST['keywords'])));
and this my output
sample products products sample
Here I don't want to replace comma also.
The input is
sample products!@, products#$#, sample
Решение
If you don't want to get rid of ,
s, you can add them to your group in the square brackets:
preg_replace("/[^, \w]+/", '',($_POST['keywords']))
Другие советы
try this
$keywords = preg_replace("/[^A-Z, ]/i", '',($_POST['keywords']));
echo $keywords;
Note: this replaces the content which does not match with the regex. Here it replaces anything except alpabets(case in-sensitive ) and comma ,
and blank space