djtozz Posted September 29, 2009 Share Posted September 29, 2009 Hello, I would like to grab the file size from a file hosted on rapidshare. sample link: http://rapidshare.com/files/160952303/Criminal.Minds.S04E06.part2.rar The following code works, (it grabs the data between <font>and </font> preg_match("#<font[^>]*?>(.*?)<\/font>#",$index,$match); and gives me following result: | 104857 KB Now I would like to remove the "|" character and the space before the filesize so I can store "104857 KB" Can anybode advice me please? Thanks. Quote Link to comment Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 Assuming that every time you have just a | and a space before the file size you can use substr() eg. $str = '| 104857 KB'; echo substr($str, 2); // "104857 KB" Quote Link to comment Share on other sites More sharing options...
djtozz Posted September 29, 2009 Author Share Posted September 29, 2009 Assuming that every time you have just a | and a space before the file size you can use substr() eg. $str = '| 104857 KB'; echo substr($str, 2); // "104857 KB" Thanks for the reaction, I'm not how to integrate this in my code, basicly the script first checks if the download is still availible, then it grabs the filesize and write it in a log file and mysql table. if($row[2]==1) // rapidshare check { $index=getpage($row[1]); if(strpos($index,"<p><script>alert(\"File not found.\")</script>File not found.</p>")===false && strpos($index,"This file has been deleted.")===false) { preg_match("/<form action=\"([^\"]+)\" method=\"post\">/",$index,$match); //print $index; if($match[1]) { $fpath=$match[1]; $index=getpage($fpath,"dl.start=Free",$row[1]); preg_match("#<font[^>]*?>(.*?)<\/font>#",$index,$match); $fsize=0; if($match[1]) $fsize=mysql_real_escape_string(strip_tags($match[1])); print $fsize."\n"; logstr("log-c.txt",$fsize."\n"); mysql_query("UPDATE `v2links` SET `checked`='1',`fsize`='$fsize',`lastcheck`=NOW() WHERE `id`=".$row[0]); if(mysql_errno()) print mysql_error()."\n"; } Thanks Quote Link to comment Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 Change if($match[1]) $fsize=mysql_real_escape_string(strip_tags($match[1])); to if($match[1]) $fsize= substr(mysql_real_escape_string(strip_tags($match[1])), 2); Quote Link to comment Share on other sites More sharing options...
djtozz Posted September 29, 2009 Author Share Posted September 29, 2009 *EDITED* Quote Link to comment Share on other sites More sharing options...
Alex Posted September 29, 2009 Share Posted September 29, 2009 I'm not sure what you mean.. Previously this: if($match[1]) $fsize=mysql_real_escape_string(strip_tags($match[1])); was setting $fsize to something like | 104857 KB, right? Quote Link to comment Share on other sites More sharing options...
djtozz Posted September 29, 2009 Author Share Posted September 29, 2009 I'm not sure what you mean.. Previously this: if($match[1]) $fsize=mysql_real_escape_string(strip_tags($match[1])); was setting $fsize to something like | 104857 KB, right? I'm sorry... I made a little typo! It's working perfect! Thanks for your time! Apriciated! Quote Link to comment 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.