How to modify the code so that it can get all the picture?

I would like to adjust some pictures size. I used this code:

<?php
preg_match_all(‘/<img[^>]width=\“[1-9]\d{2}\” height=\“[1-9]\d{2}\”[^>]\/>/is’, $s, $matches);
$firstimg = $matches[0][0];
$newimg = preg_replace(‘/width=\“\d+\” height=\“\d+\”/’, ‘width=“300” height=“200”’, $firstimg);
echo $newimg;
?>

But it can not show all the pictures, when the picture rule is <img src=“” alt=“” title=“” /> There is no width and height, it can not work,
how to add a width and height to these kind of pictures?
Thanks.