title: PHP preg_replace to replace img tags and move them within html text
body: <p>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: <code>"Hel&lt;img .../&gt;lo My name is Alfred&lt;br/&gt;"</code>. If I just erase the style attribute (generally coming with display:float), the image breaks the text, making it horrible to read.</p>
  
  <p><strong>My solution is:</strong> using preg_replace, I "clean" all image tags, BUT then I need to take those tags and place them after the next <code>&lt;br/&gt;</code>, <code>&lt;/p&gt;</code>, etc. (every final of paragraph tag). I think it will at least make the page more readable and organized.</p>
  
  <p><strong>The problem:</strong> 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.</p>
  
  <p>Example--></p>
  
  <p><strong>before:</strong> </p>
  
  <pre><code>Hell&lt;img .../&gt;o my name is Alfred.&lt;br/&gt;
  &lt;p&gt;I come &lt;img .../&gt;from England&lt;/p&gt;
  </code></pre>
  
  <p><strong>after:</strong> </p>
  
  <pre><code>Hello my name is Alfred&lt;br/&gt;
  &lt;img .../&gt;
  &lt;p&gt;I come from England&lt;/p&gt;
  &lt;img .../&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT ---</p>
  
  <p><strong>My doubt is:</strong> if I found an img tag (<code>&lt;img /&gt;</code>) 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?</p>