我有一个我要过滤的字符串。 我想找到一些我想用 我的代码: strong> p>
preg_replace code>替换的单词。 我的参数是我想从字符串中取出的一系列单词,而我的替换只是一个空白区域。 有人可以帮我解决这个问题。 p>
$ str =“你好 这是美好的一天。“;
$ para = array(”world“,”day“);
$ newstr = preg_replace('/ \ b($ para)\ b /','',$ str );
echo $ newstr;
code> pre>
div>
I have a string which I want to filter. I want to find some words which I want to replace using preg_replace
. My parameters are an array of words I want to take out from my string, and my replacements is just an empty space. Can someone please help me to solve this problem.
My Code:
$str = "Hello world. It's a beautiful day.";
$para = array("world","day");
$newstr = preg_replace('/\b($para)\b/','',$str);
echo $newstr;