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

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

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

c++ - Redefined variable in the other module -