In regular expressions, I'm still new.

I have a text, it has a lot of spans in styles that have different font-size . We must all bring them to one. I'm going to use something like str_replace() , something like this: str_replace("/font-size: [любая цифра]px;/","font-size: 28px;,$sting") . Tell me, please, what expression to put there, and whether I approached the question correctly - maybe there is no str_replace() there!

  • I can give you a book on a regular basis for 2015, on ozone 2000R it costs - user33274
  • Not str_replace, but preg_replace. And if the work of a one-time text can be processed on regex101.com. There and debug your regular season (the regular season you need is written after 10 minutes of reading the article in Wikipedia) - Mike
  • @LenovoID, book in electronic form? - Sasha Chernykh
  • one
    but of course in electronic form => cloud.mail.ru/public/4AoB/1eebx7aSM - user33274

1 answer 1

To replace by a regular expression, you must use the preg_replace function. The number in the regular season can be written in various ways, but if not perverted, then the most popular ones (that is, the correct ones) look like this: \d+ or [0-9]+ . In the first case, you use the character class that already exists in the kernel, in the second, you create your own. + says that a character from a character class must occur at least 1 time, that is, the first digit is set. Then the greedy algorithm immediately eats up all the digits following the first one, so the regular seizes the entire number.

Your code will look like this:

 preg_replace('/font-size: \d+px;/', 'font-size: 28px;', $sting);