Help create a regular expression (if possible) to find all the tags with src and add something else to the existing values. Example:

img src = '1'

AFTER

img src = 'path / 1'

    2 answers 2

    $string=preg_replace("/src\s?=\s?(['\"])(\w+)/iu", "src=\$1вставка\$2", $string); 
    • <iframe src = "source.html"> </ iframe> - korytoff
    • <?php $string = "<iframe src=\"source.html\"></iframe> bla bla bla src='oops' src=\"motherfucker\""; echo htmlspecialchars(preg_replace("/src=['\"](\w+)/iu", "src=\"вставка\$1", $string)); ?> <?php $string = "<iframe src=\"source.html\"></iframe> bla bla bla src='oops' src=\"motherfucker\""; echo htmlspecialchars(preg_replace("/src=['\"](\w+)/iu", "src=\"вставка\$1", $string)); ?> => <iframe src="вставкаsource.html"></iframe> bla bla bla src="вставкаoops' src="вставкаmotherfucker" - Darth
    • I understand the author is exactly the img needed, although now there is no question of re-reading the question of confidence)) my first comment was to the fact that the iframe should not fall under the replacement just - korytoff
    • And why in your version grouping $1 ? Which by the way does not include http:// , // , .html or .jpg , etc. - korytoff
    • I am a programmer and read everything as it is written - find all tags with src and add something else to the existing values - Darth

    If you need to replace it and exactly with the img tags, you can do this:

     $str = '<body> <img src="photo1.jpg" /> <img class="pic" data-myattr="id100500" src="/PHOTO2.jpg"> </body>'; $result = preg_replace("/(<img[a-z0-9\"'= -]+src=['|\"])\/?([a-z0-9\.\/]+)/i", "$1http://mysite.com/$2", $str); echo $result; 

    PS: I wonder if people are completely lazy? Have you at least done something to solve your problem?

    • There is very little experience in working with regulars. It all comes down to [a-z0-9]. I’ve dug nothing on the internet. I study and it burns to find a solution faster. Sorry) - Vlad