Convert uppercase matches to bold using regex

后端 未结 2 768
忘掉有多难
忘掉有多难 2021-01-21 23:07

i need to find all uppercase words in a string and set it bold

$_POST[\'descricao\'] = \"UPPERCASE test WORD\"
$_POST[\'descricao\'] = preg_replace(\"\\b[A-Z]{2,         


        
2条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-21 23:52

    You need to capture the group and enclose the pattern:

    preg_replace("/\b([A-Z]{2,})\b/", "\\1", $_POST['descricao']);
    

提交回复
热议问题