<?php
function get_images($file,$url){
$regs=array();
$images=array();
preg_match_all('/<s?img(.*?)>/i',$file,$regs);
foreach($regs[0] as $key=>$value){
$items = explode('=',$value);
$count = count($items);
for($i=0;$i<$count;$i++){
$item = str_replace(strrchr($items[$i+1],' '),'',$items[$i+1]);
$item = trim(preg_replace('/("|')/','',$item));
if(preg_match('/src/i',$items[$i])){
if(trim($item)!=''){
if(preg_match('/((.*)(.gif|.jpeg|.jpg|.png))(.*)/',$item,$reg)){
$images[$key]['src']=find_true_path($url,$reg[1]);
}
}else{
continue;
}
}
elseif(preg_match('/alt/i',$items[$i])){
if($item!=''){
if(isset($images[$key]['src'])){
$images[$key]['alt']=$item;
}else{
continue;
}
}else{
continue;
}
}
elseif(preg_match('/title/i',$items[$i])){
if($item!=''){
if(isset($images[$key]['src'])){
$images[$key]['title']=preg_replace('/["']/','',$item);
}else{
continue;
}
}else{
continue;
}
}else{
continue;
}
}
}
return($images);
}
function find_true_path($url,$image_location){
if(preg_match('/http/',$image_location)){
return($image_location);
}else{
$true_location='';
if(substr($image_location,0,2)=='./'){
$image_location=substr($image_location,2);
}
elseif(substr($image_location,0,1)=='/'){
$image_location=substr($image_location,1);
}else{
$image_location=$image_location;
}
$back_folder_count = substr_count($image_location,'../');
$url = substr($url,0,strrpos($url,'/'));
for($i=0;$i<$back_folder_count;$i++){
if(strrpos($url,'/')==strlen($url)-1){
$url = substr($url,0,-1);
$url = substr($url,0,strrpos($url,'/'));
}else{
$url = substr($url,0,strrpos($url,'/'));
}
}
if(substr($url,-1)!='/'){
$url = $url.'/';
}
$image_location = preg_replace('/(../)/','',$image_location);
$true_location = $url.$image_location;
return($true_location);
}
}
?>
Remove images from html
Leave a Reply
You must be logged in to post a comment.