Mostrando postagens com marcador preg_match_all. Mostrar todas as postagens
Mostrando postagens com marcador preg_match_all. Mostrar todas as postagens

Função php para pegar cotação do dolar para real

<?php  
     function cotacaoDolar(){  
       $url = "http://www.dolarhoje.net.br";  
       $ch = curl_init();  
        $timeout = 0;  
        curl_setopt($ch, CURLOPT_URL, $url);  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);  
        $cont = curl_exec ($ch);  
        curl_close($ch);  
        $cont = preg_replace('/\n/',' ', $cont);  
        $cont = preg_replace('/\s/',' ', $cont);  
        $exp = '<span.*?id="moeda".*?> = R\$(.*?)<\/span>';  
        preg_match_all("@".$exp."@" ,$cont , $retorno);   
        $resp = str_replace(",", ".", $retorno[1][0]);  
        return $resp;  
     }  
 ?>  

Expressão regular para extrair o domínio de algum site

Se este código foi útil ou tenha alguma dúvida ou encontrou algum erro, deixei seu comentário.

<?php
$exp = "[http:\/\/|www.|http:\/\/www.]+(([a-z0-9]{2,})(.[a-z0-9]{2,})?(.[a-z]{3,})(.[a-z]{2,})?)";
$site = "www.seusite.com.br";

preg_match_all("@$exp@", $site, $resultado);

print_r($resultado[1][0]);  
//resultado: seusite.com.br
?>