Ronnie Ronnie - 10 months ago 18
PHP Question

PHP - How to find numbers and bold that numbers in a string

How I can make all the numbers in a string bold?

For example:

$st_nu = "Today123"
would become


You can use a regular expression to bolden only numbers.

preg_replace('/(\d+)/', '<b>$1</b>', $st_nu);

What this does is matches any number 1 or more characters long, then surrounds it with the <b> tag (bold).

Using your example, you'd get back the following: