KingdomTubes Posted January 27, 2012 Share Posted January 27, 2012 Hello, I'm requesting your help here cause I'm really confused. I'm looking for deleting entries when an image doesn't load on my links test. I got all my links in a .txt file like this : links.txt = <div class="gallery"> <a href="http://www.website.com/page"> <img src="http://tc16.easythumbhost.com/image.jpg" onerror="ImgError(this)"/> </a> </div> #enddiv the "onerror" code in img src sends an "Image Missing" pic. What I'd want is to change the "onerror" function to open a php script which deletes all the lines of the div. This is the script I use to show the links on my page : $links = "links.txt"; $fd = fopen ($links, "r"); $content = fread ($fd,filesize ($links)); fclose ($fd); $delimiter = "#enddiv"; $splitcontent = explode($delimiter, $content); $output = array_slice($splitcontent, 0,100); foreach ( $output as $divs ) { echo "$divs"; } I've searched hours and tried lots of codes before posting Help would be very appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/ Share on other sites More sharing options...
trq Posted January 28, 2012 Share Posted January 28, 2012 Is there a particular reason your not using a database for this? I think your making it more difficult then it needs to be. Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/#findComment-1311889 Share on other sites More sharing options...
KingdomTubes Posted January 28, 2012 Author Share Posted January 28, 2012 I'm a bit new in all of this.. I began doing websites three months ago and learning it all by myself. I didn't know the possibility of database, I'll search about it. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/#findComment-1311932 Share on other sites More sharing options...
KingdomTubes Posted January 28, 2012 Author Share Posted January 28, 2012 could you give me some hints where to search for please(if you understand my problem for sure)? This would help me a lot Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/#findComment-1311935 Share on other sites More sharing options...
KingdomTubes Posted January 29, 2012 Author Share Posted January 29, 2012 Since I had no idea how to make a database I continued this way, and this is the result. I called this function "onerror" function ImgError(data) { xmlhttp.open("POST","missing_image.php",false); xmlhttp.send('src='+data.src); data.src = "../../images/brokenlink.jpg"; } created a missing_image.php with this the following code <?php $src = isset($_POST['src']) ? $_POST['src'] : NULL; if( is_null($src) ) exit; $file = file_get_contents('links.txt'); $pattern = '/<div[^>]+>\s<a[^>]+>\s<img src="'.preg_quote($src,'/').'"[^>]+>\s</a>\s</div>/'; if( preg_match($pattern,$file,$match) ) { $newfile = str_replace($match[0],'',$file); file_put_contents('links.txt',$newfile); } ?> Still not working.. Any idea? (Thanks to Derokorian for the codes) Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/#findComment-1312110 Share on other sites More sharing options...
devWhiz Posted January 29, 2012 Share Posted January 29, 2012 http://php.net/manual/en/book.mysql.php refer to that to learn more about databases Quote Link to comment https://forums.phpfreaks.com/topic/255902-read-delete-entries-in-txt-file/#findComment-1312111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.