Taking a single value for PHP

3
$ch = curl_init('site');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/6.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.7) Gecko/20050414 Firefox/1.0.3");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'x.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'x.txt');
$html = curl_exec($ch);
$dom = new DOMDocument();

@$dom->loadHTML($html);

$link = array();
foreach($dom->getElementsByTagName('a') as $link) {
  # Mostrar todos os elemento que estiver dentro da tag href


$x = $link->getAttribute('href'); // exibi todos os conteudo dentro do href !
// pegar apenas o link completo
#https://www.site.com/checkout.asp?ref=fvFDGND2MYQ

///
echo $x;

So that way I can get all the html links received from cURL

link

and for me just get the link ? just this link?

    
asked by anonymous 18.12.2014 / 22:11

1 answer

1

If you want a particular link , you can check the content of the link to see if it is what you want:

// ...
foreach ($dom->getElementsByTagName('a') as $link) {

  /* Verifica se é o link que eu quero
   */
  $href = $link->getAttribute('href');
  if (strpos($href, "checkout.asp?ref=") !== FALSE) {
    $x = $href;  // guarda o link
    break;       // sair do ciclo
  }
}
                                    
18.12.2014 / 22:31