Whenever the voltage exceeds a certain threshold (perhaps useful for non-browser users if (preg_match("@.*(get_img_tags($xpath, "//div[@class='singleImage']/img[@class='magicfields']", $article); $article['content'] = $img_tag . $article['content']; } Added.