str_get_html and simply html dom
<p>way after str_replace function $img is empty and secont $img->find('img') function show error:</p>

<pre><code>Fatal error: Cannot use object of type simple_html_dom as array in D:\wamp\www\test.php on line 7

   &lt;?php
require_once('simple_html_dom.php');

$img_html = str_get_html('hhtml tekst html tekst &lt;img src = "img.png" /&gt; ad sad');

foreach($img_html-&gt;find('img') as $element)
    $img[] = $element-&gt;src . '&lt;br&gt;';

$img_html = str_replace($img[0], 'n-'.$img[0], $img_html);    

foreach($img_html-&gt;find('img') as $element2)
    echo $element2-&gt;src . '&lt;br&gt;';
?&gt;
</code></pre>
