There is a piece of view code:

<p><strong>не важный текст</strong></p> <p><strong>нужный текст</strong></p> <p><strong>не важный текст</strong></p> 

It is necessary after <p> with the necessary text to insert there is another tag

, preferably using a regular expression, <p> has variation with style="" and without

  • use the preg_replace () function. - Edward
  • the question is rather in the selection of the regular expression itself, the functions that I need to use - I know - Timofey Semenyuk
  • @ Timofey Semenyuk describe the problem in more detail. - Kirill Korushkin
  • @KirillKorushkin There is a complete description of the product in the <p><strong>Габаритные размеры (мм) (ШхГхВ): 1000х1000х1000</strong></p> , after that you need to insert some more text - Timofey Semenyuk
  • At what stage of the page rendering should the text be inserted? And what is the source of this text? - Kirill Korushkin

1 answer 1

Find the тэг <p> с любыми аттрибутами , replace with то что нашли + дополнительный текст :

 $ php -r "echo preg_replace('/(<p[^>]*>)/', '\$1foo', '<p><strong>текст</strong></p>') . PHP_EOL;" <p>foo<strong>текст</strong></p> 
  • Almost, but the problem is that there are many such tags and unique in relation to others only its content. Габаритные размеры (мм) (ШхГхВ): 1000х1000х1000 - Timofey Semenyuk
  • then this is /(<p[^>]*>)/ change to /(<p[^>]*>)(уникальный-текст-детектор)/ . Add the same text in the second argument as $2 . and even better update the question, because Now his production does not reflect these of your nuances. - Lexx918