This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Bad Email... | |
$badEmail = "bad@email"; | |
//Run the email through an email validation filter. | |
if( !filter_var($badEmail, FILTER_VALIDATE_EMAIL) ){ | |
echo "Email is no good."; | |
}else{ | |
echo "Nice email."; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Upload multiple files with php | |
<?php | |
fixFilesArray($_FILES['array_of_files']); | |
foreach ($_FILES['array_of_files'] as $position => $file) { | |
// should output array with indices name, type, tmp_name, error, size | |
var_dump($file); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retorna todos os status do Correios para ID enviado | |
* | |
* @param string $id_correios ID do Correios | |
* @return array $array_retorno | |
*/ | |
function status_correios( $id_correios ) { | |
$conteudo = file_get_contents('http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI='.$id_correios); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Recentemente publicamos o artigo: Descompactando arquivos vai SSH. E hoje aprenderemos como compactar estes arquivos. | |
Quem tem um site ou qualquer hospedagem que armazene arquivos sabe que eventualmente são necessários backups, seja para corrigir algum erro ou problema que tenha dado (muito comuns quando estamos fazendo a periódica manutenção do portal). O grande problema é quando alguma coisa dá errado e não conseguimos restaurar nossos arquivos para antes do problema ter ocorrido. | |
Hoje a maioria dos provedores de hospedagem possuem um backup automático onde basta o cliente solicitar o dia e hora que seus arquivos serão restaurados. | |
O grande problema é: Tempo. | |
Recentemente passei pela inconveniente necessidade de recuperar uns arquivos antigos e tive que pedir ao meu provedor para restaurar até determinada hora. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$num=103; | |
if($num & 1) { | |
#impar | |
return true; | |
} else { | |
#par | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* usage: echo tweetCount('http://google.com'); | |
* ref: http://www.phpsnippets.info/get-how-many-times-a-page-have-been-retweeted-using-php | |
*/ | |
function tweetCount($url) { | |
$content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url); | |
$element = new SimpleXmlElement($content); | |
$retweets = $element->story->url_count; | |
if($retweets){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Calcula distancias | |
*/ | |
function distance($lat1, $lon1, $lat2, $lon2, $unit) { | |
$theta = $lon1 - $lon2; | |
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); | |
$dist = acos($dist); | |
$dist = rad2deg($dist); | |
$miles = $dist * 60 * 1.1515; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Mais informações | |
// http://www.delicious.com/help/feeds | |
// Count | |
function delicious_count($url) { | |
$count = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#vc dentro de Iframeid | |
parent.document.getElementById("IframeId"); | |
#vc fora dos iframes tentando chamar uma funcão javascript que está dentro de um iframe | |
document.getElementById("IframeId").contentWindow.HelloWorld(); | |
#pegar conteúdo do iframe | |
var iframe = parent.document.getElementById( "iframeReport"); | |
var innerDoc = iframe.contentDocument || iframe.contentWindow.document; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## based on http://www.developerzen.com/2011/01/10/show-the-current-git-branch-in-your-command-prompt/ | |
function parse_git_branch () { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
BLUE="[\033[0;34m\]" | |
DARK_BLUE="[\033[1;34m\]" | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[0;33m\]" |
OlderNewer