我需要在字符串中找到所有大写单词并将其设置为粗体
$_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>
答案 0 :(得分:3)
您需要捕获该组并将模式括起来:
preg_replace("/\b([A-Z]{2,})\b/", "<b>\\1</b>", $_POST['descricao']);
答案 1 :(得分:0)
使用此:
$_POST['descricao'] = "UPPERCASE test WORD"
$_POST['descricao'] = preg_replace("/\b([A-Z]{2,})\b/", "<b>$1</b>", $_POST['descricao']);