Guest User

Untitled

a guest
Jan 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.06 KB | None | 0 0
  1. <?php
  2.  
  3. function anti_injection($sql)
  4. {
  5.     // remove palavras que contenham sintaxe sql
  6.     //$sql = preg_replace(sql_regcase("/(from|select|insert|delete|where|drop table|show tables|#|\*|--|\\\\)/"),"",$sql);
  7.     $sql = trim($sql);//limpa espaços vazio
  8.     $sql = strip_tags($sql);//tira tags html e php
  9.     $sql = addslashes($sql);//Adiciona barras invertidas a uma string
  10.     return $sql;
  11. }
  12.  
  13. //-------------------------- REMOCAO DE ACENTUACAO -----------------------------------------------------------
  14. function remove_acentos($str)
  15. {
  16.     $s = $str;
  17.     $s = ereg_replace("[áàâãª]","a",$s);
  18.     $s = ereg_replace("[ÁÀÂÃ]","A",$s);
  19.     $s = ereg_replace("[éèê]","e",$s);
  20.     $s = ereg_replace("[ÉÈÊ]","E",$s);
  21.     $s = ereg_replace("[íìî]","i",$s);
  22.     $s = ereg_replace("[ÍÌÎ]","I",$s);
  23.     $s = ereg_replace("[óòôõº]","o",$s);
  24.     $s = ereg_replace("[ÓÒÔÕ]","O",$s);
  25.     $s = ereg_replace("[úùû]","u",$s);
  26.     $s = ereg_replace("[ÚÙÛ]","U",$s);
  27.     $s = str_replace("ç","c",$s);
  28.     $s = str_replace("Ç","C",$s);
  29.    
  30.     return $s;
  31. }
  32.  
  33. //Usar em scripts executados via ajax (UTF8) ---------------
  34. function remove_acentos_ajax($var, $enc = "UTF-8")
  35. {
  36.     $acentos = array(
  37.         'A' => '/&Agrave;|&Aacute;|&Acirc;|&Atilde;|&Auml;|&Aring;/',
  38.         'a' => '/&agrave;|&aacute;|&acirc;|&atilde;|&auml;|&aring;/',
  39.         'C' => '/&Ccedil;/',
  40.         'c' => '/&ccedil;/',
  41.         'E' => '/&Egrave;|&Eacute;|&Ecirc;|&Euml;/',
  42.         'e' => '/&egrave;|&eacute;|&ecirc;|&euml;/',
  43.         'I' => '/&Igrave;|&Iacute;|&Icirc;|&Iuml;/',
  44.         'i' => '/&igrave;|&iacute;|&icirc;|&iuml;/',
  45.         'N' => '/&Ntilde;/',
  46.         'n' => '/&ntilde;/',
  47.         'O' => '/&Ograve;|&Oacute;|&Ocirc;|&Otilde;|&Ouml;/',
  48.         'o' => '/&ograve;|&oacute;|&ocirc;|&otilde;|&ouml;/',
  49.         'U' => '/&Ugrave;|&Uacute;|&Ucirc;|&Uuml;/',
  50.         'u' => '/&ugrave;|&uacute;|&ucirc;|&uuml;/',
  51.         'Y' => '/&Yacute;/',
  52.         'y' => '/&yacute;|&yuml;/',
  53.         'a.' => '/&ordf;/',
  54.         'o.' => '/&ordm;/');
  55.  
  56.     return preg_replace($acentos, array_keys($acentos), htmlentities($var, ENT_NOQUOTES, $enc));
  57. }
  58. //---------------------------------------------------------------------------------------------------------
  59.  
  60. //mantem apenas numeros (retira o restante);   
  61. function apenas_numeros($str)
  62. {
  63.     ereg_replace("[^0-9]", "", $str);
  64.     return $str;
  65. }
  66.  
  67. //Converter valor no formato 15.000,50 para o formato mysql 15000.50
  68. function converter_valor_mysql($valor)
  69. {
  70.     $valor = str_replace(" ", "", $valor);
  71.     $valor = str_replace(".", "", $valor);
  72.     $valor = str_replace(",", ".", $valor);
  73.    
  74.     return $valor;
  75. }
  76.  
  77. function contar_registros($q)
  78. {
  79.     $res = mysql_query($q) or die(mysql_error());  
  80.     $tpl = mysql_fetch_array($res);
  81.    
  82.     return $tpl[0];
  83. }
  84.  
  85. function formatar_data($d)
  86. {
  87.     //passar data do formato do mysql yyyy-mm-dd para formato padrão dd/mm/yyyy
  88.     $d1 = explode("-", $d);    
  89.     return  $d1[2]."/".$d1[1]."/".$d1[0];
  90. }
  91.  
  92. //passar data do formato dd/mm/yyyy para formato padrão yyyy-mm-dd
  93. function formatar_data_contrario($d)
  94. {
  95.    
  96.     $d1 = explode("/", $d);    
  97.     return  $d1[2]."-".$d1[1]."-".$d1[0];
  98. }
  99.  
  100. function formata_data_dia($d)
  101. {
  102.     //passar data do formato do mysql yyyy-mm-dd para formato padrão dd-mm-yyy
  103.     $dia    = substr($d ,6 ,2);
  104.     return  $dia;
  105. }
  106.  
  107. //Verificar se arquivo existe ------------------------------------
  108. function arquivo_existe($path_arquivo)
  109. {
  110.     if(file_exists($path_arquivo) && (is_file($path_arquivo)))
  111.         return true;
  112.     else return false;
  113. }
  114. //-----------------------------------------------------------------
  115.  
  116. //--Gerar nome de arquivos para as imagens dos produtos -------------
  117. function gerar_nome_arquivo($str)
  118. {
  119.     $str = remove_acentos(strtolower($str));
  120.    
  121.     //Trocar espaços em branco por traços
  122.     $str = str_replace(" ", "-", $str);
  123.    
  124.     //Eliminar caracteres que forem diferentes de letras, numeros ou traço
  125.     $str = preg_replace("/[^\-0-9a-zA-Z]/", "", $str);
  126.    
  127.     //Eliminar as repetições de traços
  128.     $str = preg_replace("/(\-){2,}/", "-", $str);  
  129.    
  130.     if($str[strlen($str)-1] == "-")
  131.         $str = substr($str, 0, strlen($str)-1);
  132.        
  133.     return $str;
  134. }
  135. //--/Gerar nome de arquivos para as imagens dos produtos -------------
  136.  
  137. //Verificar se um tipo de arquivo eh JPG
  138. function se_jpg($tipo)
  139. {
  140.     if( ($tipo == "image/jpeg") || ($tipo == "image/pjpeg") )
  141.         return true;
  142.     else
  143.         return false;
  144. }
  145.  
  146. //Verificar se é arquivo, se sim, exlcuir
  147. function excluir_arquivo($path)
  148. {
  149.     //verificar se (arquivo ou diretorio) existe, se sim, e se for arquivo, excluir
  150.     if((file_exists($path)) && (is_file($path)))
  151.         unlink($path);
  152. }
  153.  
  154. function obter_proporcao($img)
  155. {
  156.     //obter propoção da imagem (largura/altura)
  157.     $dimensoes  = getimagesize($img);
  158.    
  159.     $proporcao = $dimensoes[0]/$dimensoes[1];
  160.    
  161.     return $proporcao;
  162. }
  163.  
  164. function SomarData($data, $dias, $meses, $anos)
  165. {
  166.    //passe a data no formato dd/mm/aaaa
  167.    $data = explode("/", $data);
  168.    $newData = date("d/m/Y", mktime(0, 0, 0, $data[1] + $meses, $data[0] + $dias, $data[2] + $anos));
  169.    return $newData;
  170. }
  171.  
  172. //Obter a quantidade de dias entre duas datas ------------------------------------------------
  173. function contar_dias($d1, $d2)
  174. {
  175.     //datas no formato (dd/mm/aaaa)
  176.    
  177.     $data1 = explode("/", $d1);
  178.     $data2 = explode("/", $d2);
  179.    
  180.     //calculo timestamp das duas datas
  181.     $timestamp1 = mktime(0,0,0,$data1[1],$data1[0],$data1[2]);
  182.     $timestamp2 = mktime(0,0,0,$data2[1],$data2[0],$data2[2]);
  183.    
  184.     //diminuo a uma data a outra
  185.     $segundos_diferenca = $timestamp2 - $timestamp1;
  186.     //echo $segundos_diferenca;
  187.    
  188.     //converto segundos em dias
  189.     $dias_diferenca = abs(round($segundos_diferenca / (60 * 60 * 24)));
  190.    
  191.     return $dias_diferenca;
  192. }
  193. //--------------------------------------------------------------------------------------------
  194.  
  195. //Manter apenas as letras iniciais de cada palavra e maiusculas da string $str
  196. function iniciais_maiusculas($str)
  197. {
  198.     return ucwords(strtolower($str));
  199. }
  200.  
  201. //função para tratar textos gerados pelo editor de textarea (jhtml area) ------
  202. function tratar_texto($txt)
  203. {
  204.     $txt = str_replace("<div>", "", $txt);
  205.     $txt = str_replace("</div>", "", $txt);
  206.    
  207.     $txt = addslashes($txt);
  208.    
  209.     return $txt;
  210. }
  211. //-------------------------------------------------------------------------------
  212.  
  213. ?>
Add Comment
Please, Sign In to add comment