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'
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'
$string=preg_replace("/src\s?=\s?(['\"])(\w+)/iu", "src=\$1вставка\$2", $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)); ?> <?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" - Darthimg 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$1 ? Which by the way does not include http:// , // , .html or .jpg , etc. - korytoffIf 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?
Source: https://ru.stackoverflow.com/questions/469264/
All Articles