Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Nie wyświetlają się wyniki.
Forum PHP.pl > Forum > Przedszkole
szczalpi
Witam
Poniżej wkleiłem skrypt, z którym mam problem - nie wiem, którym miejscu jest błąd. Otóż wpisując adres i fraze powinny pojawić wyniki, ale się nie pojawiają. I mam problem. Może macie rozwiązanie na mój problem.


  1. <form method="get" action="google.php" style="text-align:center;">
  2. <input type="text" maxlength="100" name="fraza" class="contactForm1">
  3. <input type="text" maxlength="100" name="adres" class="contactForm1">
  4. <input type="submit" value="szukaj"/>
  5.  
  6.  
  7.  
  8. </form>
  9. <?php
  10.  
  11. $sQ = $_get["fraza"];
  12. $sPhrase = $_get["adres"];
  13. $pozycja = new checkPosition( '$sPhrase', '$sSite' );
  14.  
  15.  
  16. /*
  17. @author Piotr `shpyo` Cichosz
  18. <a href="http://blog.shpyo.net" target="_blank">http://blog.shpyo.net</a>
  19. */
  20.  
  21. class checkPosition
  22. {
  23. public $sLinkRegExp = '/<h3 class="r"><a href="([^"]+)" class=l>/';
  24. public $sURL = '';
  25. public $iLimit = 100;
  26. public static $aDC = array(
  27. 'www.google.pl'
  28. );
  29.  
  30. private $sQ = '';
  31. private $sSite = '';
  32. public $iPosition = '-';
  33.  
  34. public function __construct( $sPhrase, $sSite )
  35. {
  36. $this->sQ = $sPhrase;
  37. $this->sSite = self::getHost( $sSite );
  38. }
  39.  
  40. public function getHost( $sPage )
  41. {
  42. preg_match('@^(?:http://)?([^/]+)@i', $sPage, $matches);
  43. $matches[1] = str_replace("www.", "", $matches[1]);
  44. return $matches[1];
  45. }
  46.  
  47. public function getPhrase()
  48. {
  49. return $this->sQ;
  50. }
  51.  
  52. public function getSite()
  53. {
  54. return $this->sSite;
  55. }
  56.  
  57. public function setGoogleURL( $rDC = 'www.google.pl' )
  58. {
  59. $this->sURL = 'http://'. $rDC .'/search?hl=pl&q=%s&num='. $this->iLimit;
  60. }
  61.  
  62. public function getDC()
  63. {
  64. return self::$aDC[ mt_rand( 0, count(self::$aDC) - 1 ) ];
  65. }
  66.  
  67. public function search( $rDC = 'www.google.pl' )
  68. {
  69. $rC = curl_init();
  70. self::setGoogleURL( $rDC );
  71. curl_setopt( $rC, CURLOPT_HEADER, 0 );
  72. curl_setopt( $rC, CURLOPT_RETURNTRANSFER, 1 );
  73. curl_setopt( $rC, CURLOPT_VERBOSE, 1 );
  74. curl_setopt( $rC, CURLOPT_REFERER, $rDC );
  75. curl_setopt( $rC, CURLOPT_URL, sprintf( $this->sURL, urlencode( self::getPhrase() ) ) );
  76. $sData = curl_exec( $rC );
  77. curl_close( $rC );
  78.  
  79. preg_match_all( $this->sLinkRegExp, $sData, $aResults );
  80. $aResults = array_pop( $aResults );
  81.  
  82. $ii = 0;
  83.  
  84. for( $i=0; $i<100; $i++ )
  85. {
  86. $sPage = self::getHost($aResults[$i]);
  87.  
  88. if( $aResults[($i+1)] )
  89. {
  90. $sNext = self::getHost($aResults[($i+1)]);
  91. if( $sDomena != $sNext )
  92. {
  93. $ii++;
  94. if( $sPage == $this->sSite )
  95. {
  96. $this->iPosition = $ii;
  97. break;
  98. }
  99. }
  100. $sDomena = $sNext;
  101. }
  102. }
  103. }
  104.  
  105. }
  106. $pozycja->search();
  107. echo $pozycja->iPosition;
  108.  
  109.  
  110. ?>
markonix
$_get => $_GET.

Dalej nie patrzałem.
szczalpi
I dalej nic sad.gif
CuteOne
$pozycja = new checkPosition( '$sPhrase', '$sSite' );
zamien na to:
$pozycja = new checkPosition( $sPhrase, $sSite ); // gdzie deklarujesz $sSite?? bo jeżeli chodzi o $sQ to musisz to zamienić


$this->sSite = self::getHost( $sSite );
zamień na
$this->sSite = $this->getHost( $sSite );

i każdy self:: zamień na $this->

szczalpi
Niestety dalej error taki ze mnie laik sad.gif
Fifi209
Nigdzie nie przesyłasz post.

Przeczytaj opis do: CURLOPT_FOLLOWLOCATION, CURLOPT_POST, CURLOPT_POSTFIELDS
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.