The use of Dom to first remove and then add the width and height to the first img tag from the text.I hope it help you to save your time
<?php
$html = '
<img src="http://www.example.com/images/header.jpg" width="898" height="223" style="border-bottom:5px solid #cccccc;"/>
<img src="http://www.example.com/images/header2.jpg" width="898" height="223" style="border-bottom:5px solid #cccccc;"/>
';
$doc = DOMDocument::loadHTML($html);
$c =0;
foreach($doc->getElementsByTagName('img') as $image){
if ($c>0) continue;
foreach(array('width', 'height') as $attribute_to_remove){
echo $attribute_to_remove;
if($image->hasAttribute($attribute_to_remove)){
$image->removeAttribute($attribute_to_remove);
}
if($attribute_to_remove=='height'){
if(!$image->hasAttribute($attribute_to_remove)){
$image->setAttribute($attribute_to_remove,'220');
}}
if($attribute_to_remove=='width'){
if(!$image->hasAttribute($attribute_to_remove)){
$image->setAttribute($attribute_to_remove,'700');
}}
$c = $c+1;
}
}
echo $doc->saveHTML();