php - How can I insert text in an html element stored in a variable? -


I have a program copying text from another website and showing it.

This is accumulating text in a variable $ string .
There are variables containing html tags and I want to add text before the html tag stored in the variable. .

For example: $ string = "

I want to add code before div whose ID is game .

To add text before the divi whose ID is 'game' simply use:

  $ string = "& lt; div id = '1' & gt; div id = 'game' & gt; & lt; / div & gt;"; $ New = "TextInstruct"; $ Pos = "& lt; div id = 'game' & gt; & lt; / div & gt;"; Echo str_replace ($ pos, $ new. $ Pos, $ string);    

Comments

Popular posts from this blog

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -

sql - PostgreSQL automatically update row at specific date -

jsp - No mapping found for HTTP request with URI with annotation config Spring MVC and Jetty -