Jump to content

[SOLVED] Help using preg match


djtozz

Recommended Posts

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.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/175884-solved-help-using-preg-match/
Share on other sites

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

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.