2

我需要在字符串中找到所有大写单词并将其设置为粗体

$_POST['descricao'] = "UPPERCASE test WORD"
$_POST['descricao'] = preg_replace("\b[A-Z]{2,}\b", "<b>\\1</b>", $_POST['descricao']);

它应该返回:<b>UPPERCASE</b> test <b>WORD</b>

4

2 回答 2

4

您需要捕获组并附上模式:

preg_replace("/\b([A-Z]{2,})\b/", "<b>\\1</b>", $_POST['descricao']);
于 2013-07-25T19:25:16.973 回答
0

用这个:

$_POST['descricao'] = "UPPERCASE test WORD"
$_POST['descricao'] = preg_replace("/\b([A-Z]{2,})\b/", "<b>$1</b>", $_POST['descricao']);
于 2013-07-25T19:26:55.590 回答