Skip to content

Instantly share code, notes, and snippets.

@danilowm
Created March 8, 2012 01:50
Show Gist options
  • Select an option

  • Save danilowm/1997953 to your computer and use it in GitHub Desktop.

Select an option

Save danilowm/1997953 to your computer and use it in GitHub Desktop.
Função de Saudação (bom dia, boa tarde e boa noite)
<?php
function saudacao( $nome = '' ) {
date_default_timezone_set('America/Sao_Paulo');
$hora = date('H');
if( $hora &gt;= 6 &amp;&amp; $hora &lt;= 12 )
return 'Bom dia' . (empty($nome) ? '' : ', ' . $nome);
else if ( $hora &gt; 12 &amp;&amp; $hora &lt;=18 )
return 'Boa tarde' . (empty($nome) ? '' : ', ' . $nome);
else
return 'Boa noite' . (empty($nome) ? '' : ', ' . $nome);
}
echo saudacao();
// Irá retornar conforme o horário:
// Bom dia
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment