Çözüldü PHP aramaları filtreleme

Bu konu çözüldü olarak işaretlenmiştir. Çözülmediğini düşünüyorsanız konuyu rapor edebilirsiniz.

Randoming321

Decapat
Katılım
12 Nisan 2022
Mesajlar
438
Daha fazla  
Cinsiyet
Erkek
Selam. PHP ile Google'dan çektiğim verilerin .com'a kadar almak istiyorum ama sonundaki "/"den sonraki tokeni da alıyor, mesela example.com... Yardım ederseniz çok sevinirim.
 
Çözüm
@tam1gamer1 hocam fakat söyle bir sıkıntı olmaz değil mi www.example.com olan siteleri de alır yani example.com olarak onları es geçmez degilmi yanıtlarsanız sevinirim.
Bunu deneyerek görmek daha hızlı yanıt olacaktır ama madem sordunuz cevaplıyalım:


PHP:
<?php

    $url = 'http://google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'google.com'
   
    echo '<hr>';
   
    $url = 'http://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'
   
    echo '<hr>';
   
    $url = 'https://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'

?>

bunu deneyerek görmek daha hızlı yanıt olacaktır ama madem sordunuz cevaplıyalım:


PHP:
<?php

    $url = 'http://google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'google.com'
  
    echo '<hr>';
  
    $url = 'http://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'
  
    echo '<hr>';
  
    $url = 'https://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'

?>

Görüldüğü üzere sıkıntı olmuyor hatta SSL url de bile sıkıntı olmuyor.
PHP:
<?php

$url = "example.com/index.php?token=QWERT-QWERT-QWERT-QWERT";

$dizi = explode (".com",$url);

echo '<pre>';

print_r ($dizi);

echo '</pre>';

//Çıktı
array(
    [0] => "example.com",
    [1] => "/index.php?token=QWERT-QWERT-QWERT-QWERT"
)

?>

İyi sosyaller.
 
@tam1gamer1
<?PHP
İf($_get)
{
İnclude ('simple_html_dom.php');
$Curl = curl_init();
curl_setopt($curl,CURLOPT_URL,"https://www.google.com/search?q='".trim($_GET["ad"])."'");
Curl_setopt($curl, curlopt_followlocatıon, true);
Curl_setopt($curl, curlopt_returntransfer, true);
$Result = curl_exec($curl);
Curl_close($curl);
// Echo $result;
$Domresults = New simple_html_dom();
$Domresults->load($result);
Foreach($domresults->find('a[href^=/url]') as $link)
{
$Url=$link->href;
$Url = str_replace("/url? Q=","",$url);
$Result.= $url."\n";
Echo "<li><a ID='a' href='"$url."'>'".$url."'</a> </li><br>";

}

file_put_contents("myresult.txt", $result, fıle_append);
}?> Bu kodda nasıl filteleme yapabilirim? Mesela https://example.com&as = ujddedefrfderfwfwrfwrfrfrgefwrfwrrfrfwfwrfwrrfwwrfw bunu nasıl sadece example.com olarak alabilirim yanıtlarsanız cok memnun olurum?
 
PHP:
<?PHP
include ('simple_html_dom.php');
$Curl = curl_init();
curl_setopt($curl,CURLOPT_URL,"https://www.google.com/search?q='".trim($_GET["ad"])."'");
curl_setopt($curl, curlopt_followlocatıon, true);
curl_setopt($curl, curlopt_returntransfer, true);
$Result = curl_exec($curl);
curl_close($curl);
// Echo $result;
$Domresults = new simple_html_dom();
$Domresults->load($result);
foreach($domresults->find('a[href^=/url]') as $link)
{
$Url=$link->href;
$Url = str_replace("/url? Q=","",$url);
$Result.= $url."\n";
echo "<li><a ID='a' href='"$url."'>'".$url."'</a> </li><br>";
$domain=parse_url($url);
echo $domain['path'];

}

file_put_contents("myresult.txt", $result, fıle_append);
?>

İyi sosyaller.

@Randoming321

Hallettin mi ?
 
Son düzenleme:
Siz bir yerde hata yapıyorsunuz çünkü ben kodu denediğimde gayet güzel çalışıyor.

$url değişkenine gelen değeri kontrol ediniz.


PHP:
<?php

    $url = 'http://google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'google.com'

?>

@Randoming321
 
Son düzenleme:
@tam1gamer1 hocam fakat söyle bir sıkıntı olmaz değil mi www.example.com olan siteleri de alır yani example.com olarak onları es geçmez degilmi yanıtlarsanız sevinirim.
Bunu deneyerek görmek daha hızlı yanıt olacaktır ama madem sordunuz cevaplıyalım:


PHP:
<?php

    $url = 'http://google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'google.com'
   
    echo '<hr>';
   
    $url = 'http://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'
   
    echo '<hr>';
   
    $url = 'https://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'

?>

bunu deneyerek görmek daha hızlı yanıt olacaktır ama madem sordunuz cevaplıyalım:


PHP:
<?php

    $url = 'http://google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'google.com'
  
    echo '<hr>';
  
    $url = 'http://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'
  
    echo '<hr>';
  
    $url = 'https://www.google.com/test/test2/test3/index.html';
    $parse = parse_url($url);
    echo $parse['host']; //'www.google.com'

?>

Görüldüğü üzere sıkıntı olmuyor hatta SSL url de bile sıkıntı olmuyor.
 
Çözüm

Technopat Haberler

Yeni konular

Geri
Yukarı