Frage

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,}\b", "<b>\\1</b>", $_POST['descricao']);

it should return: <b>UPPERCASE</b> test <b>WORD</b>

War es hilfreich?

Lösung

You need to capture the group and enclose the pattern:

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

Andere Tipps

Use this:

$_POST['descricao'] = "UPPERCASE test WORD"
$_POST['descricao'] = preg_replace("/\b([A-Z]{2,})\b/", "<b>$1</b>", $_POST['descricao']);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top