Advertisement
garfield

[PHP]: Manipulação de arquivos de texto utilizando TAGS.

Feb 10th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2.  
  3. /*                 
  4.                         @Autor: SuYaNw Dácio
  5.                         @Função: Criar arquivos com formato "Tag=Valor"
  6.                         Agradecimento: Bruno da Silva.
  7. */
  8.  
  9. function file_Set($filename, $tag, $val){
  10.  
  11.     $Internal_F =  0;
  12.  
  13.  
  14.     if(file_exists($filename)) $Internal_F = 5;
  15.  
  16.     if(!file_exists($filename)) $Internal_F = 15;
  17.  
  18.  
  19.     $Contend    = "";
  20.  
  21.     if($Internal_F == 5)
  22.     {
  23.  
  24.         $Arquivo    = fopen($filename, "r");
  25.  
  26.         $Conteudo   = fread($Arquivo, filesize($filename));
  27.  
  28.         $linha      = explode("\n", $Conteudo);
  29.  
  30.  
  31.         for($i = 0; $i != sizeof($linha); $i ++)
  32.         {
  33.             if(!(strpos($linha[$i], $tag) !== false)){
  34.  
  35.                 if(!is_null($linha[$i])) $Contend .= $linha[$i]."\n";
  36.  
  37.  
  38.             }
  39.         }
  40.  
  41.         fclose($Arquivo);
  42.  
  43.         unlink($filename);
  44.  
  45.         $Internal_F = 15;
  46.     }
  47.  
  48.  
  49.  
  50.     if($Internal_F == 15){
  51.  
  52.         $Contend .= $tag."=".$val;
  53.  
  54.         $Arquivo    = fopen($filename, "w");
  55.         fwrite($Arquivo, $Contend);
  56.         fclose($Arquivo);
  57.  
  58.     }
  59.  
  60.     return true;
  61. }
  62.  
  63.  
  64. // Agradecimentos: Bruno Da Silva.
  65. function file_Get($fPlayer,$tag)
  66. {
  67.  
  68.     $fIni = parse_ini_file($fPlayer);
  69.     return $fIni[$tag];
  70. }
  71.  
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement