I have what seems like quite a simple query. I have the following code in PHP:
$newThumb = str_replace('style="width:170px;"','',$nolinkThumb);
The problem that I have is that the number '170' can be any number therefore I would like my str_replace to reflect this. I have tried using:
$newThumb = str_replace('style="width:[0-9]px;"','',$nolinkThumb);
But this doesn't work. Any help would be greatly appreciated.
Thank you
You need to use regex, but [0-9] in regex means "the digits 0 to 9 repeated once".
What you're actually searching for is [0-9]+ which means "the digits 0 to 9 repeated one or more times":
$string = preg_replace('/style="width:[0-9]+px;"/', '', $string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With