hello I have the following code :
$img= '<img src="image.png" class="image-rounded" width="100" height="100">';
and this is my code:
preg_replace("~<img\s(.|\n)*?>~i",'<img src="imageafterreplace.png" width="140" height="160">', $img);
but what I want is to get class="image-rounded" of the image too and replace it so my url will look like this:
<img src="imageafterreplace.png" width="140" height="160" class="image-rounded">
UPDATE : I'm getting urls from a website and changing them but keeping the same class so the class="" can be changed from one url to another . I already found the answer :
preg_replace('~<img\s*.*?\s*class\s*=\s*"([^"]*)"\s*.*?>~i','<img src="imageafterreplace.png" width="140" height="160" class="$1">', $img);
but my code still have a problem is that if the img tag has class attribute then it gets replaced if not it gets ignored.
what I want is some modification in my regex code to tell it if class is already in img then it gets replaced if not just let it blank