I'm developing a mobile web, which contents come from a foreign XML, and i'm having trouble with tags. They're coming with style attributes, which I think would be easy to erase using preg_replace in php before showing the contents. The problem comes when a img tag is found within a text... something like: "Hel<img .../>lo My name is Alfred<br/>". If I just erase the style attribute (generally coming with display:float), the image breaks the text, making it horrible to read.
My solution is: using preg_replace, I "clean" all image tags, BUT then I need to take those tags and place them after the next <br/>, </p>, etc. (every final of paragraph tag). I think it will at least make the page more readable and organized.
The problem: don't know how to get every img tag's index, just after I cleaned it, and then find the next end of paragraph to place it there.
Example-->
before:
Hell<img .../>o my name is Alfred.<br/>
<p>I come <img .../>from England</p>
after:
Hello my name is Alfred<br/>
<img .../>
<p>I come from England</p>
<img .../>
Thanks in advance.
EDIT ---
My doubt is: if I found an img tag (<img />) in text (maybe using preg_replace, because I first needed to find a img tag, verify its attributes and change them if necessary), how do I get the index inside the whole string (by whole string I mean the whole html document read as a string) so I could take the whole tag and move it to the next end of paragraph?
(.+?)in place of...and you got yourself a regex. With a litte effort it's possible to find something in the many duplicates such as php - Extracting from between two strings using regex, albeit many regex answers have been botched lately.<img />) in text, how do I get the index inside the whole string so I could take the whole tag and move it to the next end of paragraph?