gerkintrigg Posted November 17, 2009 Share Posted November 17, 2009 Hi everyone. I am trying to check whether the image links in a string containing HTML, is a relative link or an absolute one... in other words I need the full http://www.whatever.com/ in order to make sure that the images show correctly. I have managed to do this to a degree with this code: #ensure the images are grabbed: $src_old_content=GetBetween($page, 'src="', '"'); $pos = strpos($src_old_content, $findme); #if it doesn't begin with http:// then make it begin with that: if ($pos !== false) { } else { $src_new_content=$url.'/'.$src_old_content; } $page=str_replace($src_old_content, $src_new_content, $page); Yes I wrote a function to get what's between the start and end variables and referenced that function. The only issue I have now is that it only replaces the first occurrence of the image code in the string. I want it to replace every occurrence. Can I do that with preg_replace or do I need to use some kind of loop? Thanks. Link to comment https://forums.phpfreaks.com/topic/181933-solved-validating-images/ Share on other sites More sharing options...
gerkintrigg Posted November 18, 2009 Author Share Posted November 18, 2009 Nevermind: #ensure the images are grabbed: $img_replace=explode('src="',$old_page); foreach ($img_replace as $key => $value){ $img_path=explode('"',$value); $pos = strpos($img_path[0], $findme); #if it doesn't begin with http:// then make it begin with that: if ($pos !== false) { } else { $src_new_content=$url.'/'.$img_path[0]; } $page=str_replace($img_path[0], $src_new_content, $page); } Link to comment https://forums.phpfreaks.com/topic/181933-solved-validating-images/#findComment-959700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.