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

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -