Ronnie Ronnie - 1 year ago 51
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

Answer Source

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:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download