Skip to content

Instantly share code, notes, and snippets.

View dodopok's full-sized avatar

Douglas Araujo dodopok

View GitHub Profile
@dodopok
dodopok / gist:5038994
Created February 26, 2013 14:55
Formatar Strings PHP para qualquer formato
<?php
function __format($campo='',$mascara=''){
//remove qualquer formatação que ainda exista
$sLimpo = preg_replace("(/[' '-./ t]/)",'',$campo);
// pega o tamanho da string e da mascara
$tCampo = strlen($sLimpo);
$tMask = strlen($mascara);
if ( $tCampo > $tMask ) {
$tMaior = $tCampo;
@dodopok
dodopok / gist:5057291
Last active December 14, 2015 08:19
Array2XML
<?php
class ArrayToXML
{
/**
* The main function for converting to an XML document.
* Pass in a multi dimensional array and this recrusively loops through and builds up an XML document.
*
* @param array $data
* @param string $rootNodeName - what you want the root node to be - defaultsto data.
* @param SimpleXMLElement $xml - should only be used recursively
@dodopok
dodopok / gist:5066986
Created March 1, 2013 19:11
Konami Code - Precisa do jQuery
$(document).ready(function(){
var keys = [];
var konami = '38,38,40,40,37,39,37,39,66,65';
$(document)
.keydown(
function(e) {
keys.push( e.keyCode );
if ( keys.toString().indexOf( konami ) >= 0 ){
@dodopok
dodopok / gist:5083367
Created March 4, 2013 16:13
Ler arquivo linha por linha
<?php
$arquivo = fopen('testes.txt', 'r');
if(!$arquivo){
echo 'Não foi possível abrir o arquivo';
}
else{
while(!feof($arquivo)){
$linha = fgets($arquivo);
echo rtrim($linha) . "<br>";
@dodopok
dodopok / gist:5086380
Created March 4, 2013 22:49
Ler RSS com PHP
<?php
$feed = file_get_contents('http://feeds2.feedburner.com/ThiagoBelem/Blog');
$rss = new SimpleXmlElement($feed);
foreach($rss->channel->item as $entrada) {
echo '<p><a href="' . $entrada->link . '" title="' . $entrada->title . '">' . $entrada->title . '</a></p>';
}
?>
@dodopok
dodopok / gist:5102110
Created March 6, 2013 19:12
Sort Multiarray
<?php
$songs = array(
'1' => array('artist'=>'The Smashing Pumpkins', 'songname'=>'Soma'),
'2' => array('artist'=>'The Decemberists', 'songname'=>'The Island'),
'3' => array('artist'=>'Fleetwood Mac', 'songname' =>'Second-hand News')
);
function subval_sort($a,$subkey) {
foreach($a as $k=>$v) {
$b[$k] = strtolower($v[$subkey]);
@dodopok
dodopok / gist:5153251
Created March 13, 2013 15:32
Algorítmo
algoritmo "exercicio5"
Var
N1,N2: inteiro
Media,Produto,Quociente,Diferenca,Resto: real
inicio
escreval ("escreva dois numeros")
leia (N1)
leia (N2)
Media<-(N1+N2)/2
@dodopok
dodopok / gist:5196151
Created March 19, 2013 13:38
Exemplo E-mail
<?php
class NfesController extends ArmazenamentoAppController{
public $components = array(
'Emissor.NFePHP',
'Emissor.MailNFePHP',
);
public function enviaTeste(){
@dodopok
dodopok / gist:5206179
Created March 20, 2013 16:41
Filtro CakePHP
<!--VIEW-->
<div class="notas all">
<?php
echo $this->Html->script(array('mask'));
echo $this->Html->script(array('jquery.contextMenu'));
echo $this->Html->css(array('jquery.contextMenu'));
?>
<script>
function Mask(){
$(".CPF").mask("999.999.999-99");
<div class="btn-group">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Ações
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<?php if(in_array($nota['Nfe']['infProt_cStat'], $cStat)){ ?>
<li class="xml"><a href="/sistema/emissor/notas/consulta/<?php echo $nota['Nfe']['id'] ?>" class="context">Atualizar</a></li>
<?php } ?>
<li class="danfe"><a href="/sistema/emissor/notas/danfe/<?php echo $nota['Nfe']['id'] ?>" class="context">DANFE</a></li>