I have a html structure like below, it is random div tag and img tag, and these also store in database too.
Now I have to filter the img src in below string, to remove files not in this structure but store in directory,
whats the best way to get the src in this structure in frontend use jquery or server side use php.
Any suggestion how to do this? Thanks so much!!
in frontend
<div class="h1">content<div>
<div class="h1" style="">content</div>
<div class="h1" style="">...</div>
<div class="h2">...</div>
<div class="h1" style="">content</div>
<img src="u_img/5/1.png" style="" class="">
<div class="link" style="">link: http://...</div>
<img src="u_img/5/14.jpeg" style="" class="">
<div class="h1" style=""..</div>
<img src="u_img/5/3.png" style="" class="">
in database
<div class="h1">content<div><div class="h1" style="">content</div><div class="h1" style="">...</div><div class="h2">...</div><div class="h1" style="">content</div><img src="u_img/5/1.png" style="" class=""><div class="link" style="">link: http://...</div><img src="u_img/5/14.jpeg" style="" class=""><div class="h1" style=""..</div><img src="u_img/5/3.png" style="" class="">
UPDATE
if I get those img src in frontend store in array post via jquery to php file like below, then how to delete those file not in this array
var srcArray=$('img').map(function(){
return $(this).attr('src');
});
var fd = new FormData(uf[0]);
fd.append('srcArray',srcArray);
$.ajax({
type: "POST", url: "img_clean.php",
data: fd,
processData: false, contentType: false,
})
php
$srcArray = $_POST['srcArray'];
//How to delete file not in the array?
foreach($srcArray as $row){
$dir = "u_img_p/".$id;
//unlink($dir.'/'.$row);
}
}