E.g:
<img src="http://domain.com/image.jpg"> will stay the same
<img src="/image.jpg"> will stay the same
<img src="image.jpg"> will be changed to <img src="http://domain.com/image.jpg">
I feel my code is really inefficient... Any ideas on how I could make it run with less code?
Code: Select all
preg_match_all('/<img[\s]+[^>]*src\s*=\s*[\"\']?([^\'\" >]+)[\'\" >]/i', $content_text, $matches);
if (isset($matches[1])) {
foreach($matches[1] AS $link) {
if (!preg_match("/^(https?|ftp)\:\/\//sie", $link) && !preg_match("/^\//sie", $link)) {
$full_link = get_option('siteurl') . '/' . $link;
$content_text = str_replace($link, $full_link, $content_text);
}
}
}