PHP image tag find and replace snippets - leebalaji1234/php GitHub Wiki

Find Script

`<?php // Source: http://goo.gl/qyLFbg $html = ''; preg_match( '@src="([^"]+)"@' , $html, $match ); print_r($match); $src = array_pop($match); // will return /images/image.jpg echo $src;

$html = ' '; preg_match_all( '@src="([^"]+)"@' , $html, $match );

$src = array_pop($match); print_r($src);`

Replace Script

`$str = 'src="http://www.bob.com/co/02/wp-content/uploads/2014/07/david_hasselhoff_at_the_dome_5.jpg"';

$str = preg_replace("/(src=")(.*)(/wp-content)/", "$1http://example.com$3", $str); echo $str;exit; $str = 'src="http://www.bob.com/co/02/wp-content/uploads/2014/07/david_hasselhoff_at_the_dome_5.jpg"'; `

preg_replace("/(src=\")(.*)(\/wp-content)/", "$1http://example.com$3", $str);