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
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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.