<?php

$text='<p>
  <img';
$fulltext='<p>
  <img ...... >текст</p>';
        
echo str_replace($text, '<p class="image"><img', $fulltext); 