<?php function getOgUrl( $url ) {
// Inicializa cURL
curl_setopt ( $ch , CURLOPT_FOLLOWLOCATION
, true ) ; // Seguir redirecionamentos curl_setopt ( $ch , CURLOPT_TIMEOUT
, 10 ) ; // Timeout de 10 segundos
// Executa a requisição
// Verifica se houve erro na requisição
return null ;
}
// Fecha a conexão cURL
// Carrega o HTML no DOMDocument
$dom = new DOMDocument( ) ;
$dom -> loadHTML ( $html ) ;
// Procura pela tag meta com property="og:url"
$metaTags = $dom -> getElementsByTagName ( 'meta' ) ;
foreach ( $metaTags as $meta ) {
if ( $meta -> getAttribute ( 'property' ) === 'og:url' ) {
return $meta -> getAttribute ( 'content' ) ; // Retorna o conteúdo da tag
}
}
return null ; // Retorna null se não encontrar a tag
}
// Exemplo de uso
$url = "http://w...content-available-to-author-only...o.br/scielo.php?script=sci_arttext&pid=S1519-60892024000100403&lang=pt" ; // Substitua pelo link desejado
$ogUrl = getOgUrl( $url ) ;
if ( $ogUrl ) {
echo "A URL OG é: " . $ogUrl ;
} else {
echo "Tag OG URL não encontrada." ;
} ?>
PD9waHAgZnVuY3Rpb24gZ2V0T2dVcmwoJHVybCkgewogICAgLy8gSW5pY2lhbGl6YSBjVVJMCiAgICAkY2ggPSBjdXJsX2luaXQoKTsKICAgIGN1cmxfc2V0b3B0KCRjaCwgQ1VSTE9QVF9VUkwsICR1cmwpOwogICAgY3VybF9zZXRvcHQoJGNoLCBDVVJMT1BUX1JFVFVSTlRSQU5TRkVSLCB0cnVlKTsKICAgIGN1cmxfc2V0b3B0KCRjaCwgQ1VSTE9QVF9GT0xMT1dMT0NBVElPTiwgdHJ1ZSk7IC8vIFNlZ3VpciByZWRpcmVjaW9uYW1lbnRvcwogICAgY3VybF9zZXRvcHQoJGNoLCBDVVJMT1BUX1RJTUVPVVQsIDEwKTsgLy8gVGltZW91dCBkZSAxMCBzZWd1bmRvcwoKICAgIC8vIEV4ZWN1dGEgYSByZXF1aXNpw6fDo28KICAgICRodG1sID0gY3VybF9leGVjKCRj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