Convert uppercase matches to bold using regex

后端 未结 2 723
忘掉有多难
忘掉有多难 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/", "<b>\\1</b>", $_POST['descricao']);
    
    0 讨论(0)
  • 2021-01-22 00:04

    Use this:

    $_POST['descricao'] = "UPPERCASE test WORD"
    $_POST['descricao'] = preg_replace("/\b([A-Z]{2,})\b/", "<b>$1</b>", $_POST['descricao']);
    
    0 讨论(0)
提交回复
热议问题