Apparently you want to get the Wikipedia link through a correct Google search?
Well, I just created and tested a solution for you, maybe not one of the best, however it works! :D
<?
$TermoDeBusca = urlencode('ASP World Tour'); // Termo de Busca
// Curl!
$ch = curl_init ("");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/search?q='.$TermoDeBusca);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
$html = curl_exec($ch);
// DOM!
$dom = new DOMDocument;
$dom->loadHTML($html);
$xpath = new DOMXPath($dom);
$items = $xpath->query("//h3[contains(@class, 'r')]//a"); //Pega dentro do <H3> (de classe 'r') o valor do <a>
foreach ($items as $pega){ // Loop, para cada link
$link = $pega->getAttribute('href'); // Será: http://pt.wikipedia.org/wiki/ASP_World_Tour
if (strpos($link,'wikipedia.org') == true) { // Verifica se o $link contem o 'wikipedia.org', ou seja, se é do wikipedia ~~ gambiarra
echo $link.'<br>'; // se for, ele mostra o link
} // fimse
} //fim do foreach
?>
I tried to comment as much as I could, unfortunately I don’t have time for that.
I did what I could! D
Hey, which regex could I use to find a wikipedia url? I was trying with one of these
(.*).wikipedia.org\/wiki\/(.*)[ ]+
– Vinícius Lara
@user3163662 This will depend on what you are doing, a Regex may not even be the ideal shape. Open a question with an example of the code and it will be easy to help.
– Zuul