【发布时间】:2012-06-01 16:53:30
【问题描述】:
我有一个字符串,其中每个单词的所有开头都大写。现在我想过滤它,如果它可以检测到单词链接“as, the, of, in, etc”,它将被转换为小写。我有一个代码可以替换并将其转换为小写,但只有 1 个单词,如下所示:
$str = "This Is A Sample String Of Hello World";
$str = preg_replace('/\bOf\b/', 'of', $str);
output: This Is A Sample String of Hello World
所以我想要的是过滤其他单词,例如像“is, a”这样的字符串。为每个要过滤的单词重复 preg_replace 很奇怪。
谢谢!
【问题讨论】:
-
...将所有单词组合成一个正则表达式也很奇怪。
标签: php string preg-replace