Friday, 10 November 2017

How to replace double quoted string with bold


Question: How to replace double quoted string with bold in PHP?

$description='Hello "dude", how are you?';
echo preg_replace('/"([^"]+)"/', '<strong>$1</strong>', $description);


Output
Hello dude, how are you?




Question: How to replace bracket string with italic in PHP?

$description='Hello (dude), how are you?';
echo preg_replace('/\(([^)]+)\)/', '<i>$1</i>', $description);


Output
Hello dude, how are you?