Este exemplo retira o excesso de linhas e espaços em branco de uma string.
preg_replace('/\s\s+/', ' ', $str);
Este exemplo retira o excesso de linhas e espaços em branco de uma string.
preg_replace('/\s\s+/', ' ', $str);
<?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;
}
?>
public static function dias_NaoUteis($datainicial, $datafinal) {
if (!isset($datainicial))
return false;
if (!isset($datafinal))
$datafinal = time();
$segundos_datainicial = strtotime(preg_replace('#(\d{2})/(\d{2})/(\d{4})#', '$3/$2/$1', $datainicial));
$segundos_datafinal = strtotime(preg_replace('#(\d{2})/(\d{2})/(\d{4})#', '$3/$2/$1', $datafinal));
$dias = abs(floor(floor(($segundos_datafinal - $segundos_datainicial) / 3600) / 24));
$aWhile = array();
$uteis = 0;
$nao_uteis = 0;
for ($i = 1; $i <= $dias; $i++) {
$diai = $segundos_datainicial + ($i * 3600 * 24);
$w = date('w', $diai);
if ($w == 0) {
$aWhile[] = date('d/m/Y', $diai);
$nao_uteis++;
} elseif ($w == 6) {
$aWhile[] = date('d/m/Y', $diai);
$nao_uteis++;
} else {
$uteis++;
}
}
return $aWhile;
}