PHP Regex remove IMG attributes and change SRC

3

I have the following string with html :

teste = "<img src="image/teste.jpg" alt="" width="32" height="32">
<p>teste</p>
<img src="image/teste2.jpg" alt="" width="132" height="132">";

I would like a regular expression that removes the attributes, leaving only the src and adding to the contents of src a domain of all the images of the string, thus:

teste = "<img src="http://meudominio.com/image/teste.jpg"><p>teste</p><imgsrc="http://meudominio.com/image/teste2.jpg">";

Remembering that string will not always come in this order, does anyone have any idea how to do it?

    
asked by anonymous 19.08.2015 / 16:50

1 answer

1

After doing some tests I managed to make a solution, follow the link online = link

The code in php looks like this:

$html = preg_replace('#<img.+?src=[\'"]([^\'"]+)[\'"].*>#i', '<img src="http://meudominio.com/$1">', $html);
    
19.08.2015 / 19:01