title: Separating media from text with php
body: <p>I have a string that contains html composed on a text editor. Something like:</p>
  
  <pre><code>$string ='&lt;img src="http://example.com/image.jpg" alt="alt text" width="1200" height="1650" class="full"&gt;
  Lorem ipsum &lt;a href="example.com"&gt;ergo&lt;/a&gt; ipsum';
  </code></pre>
  
  <p>Other times like:</p>
  
  <pre><code>$string ='&lt;iframe src="http://example.com/" width="1200" height="1650" class="full"&gt;&lt;/iframe&gt;
  &lt;b&gt;Lorem ipsum &lt;a href="example.com"&gt;ergo&lt;/a&gt; ipsum&lt;/b&gt;'
  </code></pre>
  
  <p>Somehow I need to get media and text into separate 's but I'm not allowed to change the way content gets inputed on the string.</p>
  
  <p>Ideally I would constrain all media to a separate field but I can't do that for multiple reasons.</p>
  
  <p>I'm trying to work something out using regex but I can't get it to work.</p>
  
  <p>The closest I got was by stripping tags but that does not get rid of the text:</p>
  
  <pre><code>echo '&lt;div class="media"&gt;'.strip_tags($sting, '&lt;img&gt;&lt;iframe&gt;').'&lt;/div&gt;&lt;br&gt;';
  echo '&lt;div class="text"&gt;'.strip_tags($string, '&lt;p&gt;&lt;a&gt;&lt;b&gt;&lt;stong&gt;').'&lt;/div&gt;';
  </code></pre>
  
  <p>Any insights? There might be a really clear solution out there..</p>