문제

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;

Demo

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top