How I can make all the numbers in a string bold?
For example:
$st_nu = "Today123"
would become Today<b>123</b>
.
How I can make all the numbers in a string bold?
For example:
$st_nu = "Today123"
would become Today<b>123</b>
.
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:
Today123
See this answer to remove the numbers from the string. Then, if you want to output it to HTML, you can wrap it in a <b>
tag, or preferably use CSS to style it.
So you can do
preg_match_all('!\d+!', $st_nu, $matches);
Edit: I misunderstood your question a little. Here's a way to do it. If you have more than one number, you can loop through the matches array.
foreach ($matches as $res) {
$replaceStr = "<b>" . $res . "</b>";
str_replace($res, $replaceStr, $st_nu);
}