Skip to content
WJunction - Webmaster Forum

PHP get

Status
Not open for further replies.

Zero

Experienced Member
639
2008
58
I've used this code on my script, but for some reason its giving me a good result.

vTQE9DO.png


This is the code i used:

PHP:
else if ($site==3) {
    //$content=file_get_contents('data/tp2');
    $content=httpGet('http://thepiratebay.se/search/'.urlencode($string).'/0/99/0');
    preg_match_all('#<tr.*>(.+)</tr>#Us',$content,$m);
    $array=array();

   foreach ($m[1] as $k =>$v) {
        if (strpos($v,'detLink')===false) {
            continue;
        }
        preg_match_all('#<td.*>(.+)</td>#Us',$v,$m2);
        $array[$k]=array();
        $array[$k]['size']=0;
        foreach ($m2[1] as $k2 =>$v2) {
            switch ($k2) {
                case 0:
                $c=strip_tags($v2);
                $array[$k]['category']=substr($c,0,strpos($c,'&gt;')-1);
                break;
                case 2:
                $d=trim(strip_tags($v2));
                $array[$k]['date']=convertDate2($d);
                break;
                case 1:
                preg_match('#<a href="([^"]+)".*>(.+)</a>#Us',$v2,$m3);
                if (isset($m3[1])) {
                    $array[$k]['id']=$m3[1];
                } else {
                    $array[$k]['id']='';
                }
                $name=trim(str_replace('&nbsp;',"\n",strip_tags($m3[2])));
                $array[$k]['name']=$name;
                break;
                case 4:
                @list($num,$base)=explode('&nbsp;',trim(strip_tags($v2)));
                $array[$k]['size']=toB($num,$base);
                break;
                case 5:
                $array[$k]['seeds']=trim(strip_tags($v2));
                break;
                case 6:
                $array[$k]['peers']=trim(strip_tags($v2));
                break;
            }
        }
        if (empty($array[$k]['id']) || empty($array[$k]['category'])) {
            unset($array[$k]);
        }
    }
Any ideas why this happens? Also the word i used on search was "adobe".

Thank you
 
Last edited:

2 comments

1. Maybe the regexes in your function don't work anymore because TPB changed its layout.
2. Your piece of code is messy and unclear.
3.
I've used this code on my script, but for some reason its giving me a good result
lol
 
First of all, I wanted to let you know that the only reason why I posted in this thread is to clean up your syntax. If there is on thing on this planet that I truly hate, it's improper or gross looking syntax. When you have to debug 10,000 lines of code, it helps if everything is correctly spaced, and denoted.

Secondly, I've cleaned up your script and I've noticed two issues. One, hopefully you understand how elseif() works, if not you need to look it up here. I have a feeling that's your issue. Next, I'm not sure if you unintentionally did it, however, you were missing a '}' brace at the end of your script.

Fixed and completed code:

PHP:
elseif($site == 3) {
    //$content=file_get_contents('data/tp2');
    $content = httpGet('http://thepiratebay.se/search/'.urlencode($string).'/0/99/0');
    preg_match_all('#<tr.*>(.+)</tr>#Us',$content,$m);
    $array = array();

    foreach($m[1] as $k => $v) {
        if(strpos($v,'detLink') === false) {
            continue;
        }
        preg_match_all('#<td.*>(.+)</td>#Us', $v, $m2);
        $array[$k] = array();
        $array[$k]['size'] = 0;
        foreach($m2[1] as $k2 =>$v2) {
            switch($k2) {
                case 0:
                $c = strip_tags($v2);
                $array[$k]['category'] = substr($c, 0, strpos($c, '&gt;') - 1);
                break;

                case 2:
                $d = trim(strip_tags($v2));
                $array[$k]['date'] = convertDate2($d);
                break;

                case 1:
                preg_match('#<a href="([^"]+)".*>(.+)</a>#Us', $v2, $m3);
                if(isset($m3[1])) {
                    $array[$k]['id'] = $m3[1];
                } else {
                    $array[$k]['id'] = '';
                }
                $name = trim(str_replace('&nbsp;', "\n",strip_tags($m3[2])));
                $array[$k]['name'] = $name;
                break;

                case 4:
                @list($num, $base) = explode('&nbsp;', trim(strip_tags($v2)));
                $array[$k]['size'] = toB($num,$base);
                break;

                case 5:
                $array[$k]['seeds'] = trim(strip_tags($v2));
                break;

                case 6:
                $array[$k]['peers'] = trim(strip_tags($v2));
                break;
            }
        }
        if(empty($array[$k]['id']) || empty($array[$k]['category'])) {
            unset($array[$k]);
        }
    }  
}
 
Status
Not open for further replies.

About the author

Z
Experienced Member · Joined
639
Messages
58
Reactions
28
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom