phpDocumentor lodel-install
[ class tree: lodel-install ] [ index: lodel-install ] [ all elements ]

Source for file generatefunc.php

Documentation is available at generatefunc.php

  1. <?php
  2. /**
  3.  * Fichier utilitaire qui contient des fonctions utilisées dans generate.php
  4.  *
  5.  * PHP versions 4 et 5
  6.  *
  7.  * LODEL - Logiciel d'Edition ELectronique.
  8.  *
  9.  * Copyright (c) 2001-2002, Ghislain Picard, Marin Dacos
  10.  * Copyright (c) 2003, Ghislain Picard, Marin Dacos, Luc Santeramo, Nicolas Nutten, Anne Gentil-Beccot
  11.  * Copyright (c) 2004, Ghislain Picard, Marin Dacos, Luc Santeramo, Anne Gentil-Beccot, Bruno Cénou
  12.  * Copyright (c) 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  13.  * Copyright (c) 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  14.  * Copyright (c) 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  15.  *
  16.  * Home page: http://www.lodel.org
  17.  *
  18.  * E-Mail: lodel@lodel.org
  19.  *
  20.  * All Rights Reserved
  21.  *
  22.  * This program is free software; you can redistribute it and/or modify
  23.  * it under the terms of the GNU General Public License as published by
  24.  * the Free Software Foundation; either version 2 of the License, or
  25.  * (at your option) any later version.
  26.  *
  27.  * This program is distributed in the hope that it will be useful,
  28.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  29.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  30.  * GNU General Public License for more details.
  31.  *
  32.  * You should have received a copy of the GNU General Public License
  33.  * along with this program; if not, write to the Free Software
  34.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  35.  *
  36.  * @author Ghislain Picard
  37.  * @author Jean Lamy
  38.  * @copyright 2005, Ghislain Picard, Marin Dacos, Luc Santeramo, Gautier Poupeau, Jean Lamy, Bruno Cénou
  39.  * @copyright 2006, Marin Dacos, Luc Santeramo, Bruno Cénou, Jean Lamy, Mikaël Cixous, Sophie Malafosse
  40.  * @copyright 2007, Marin Dacos, Bruno Cénou, Sophie Malafosse, Pierre-Alain Mignot
  41.  * @licence http://www.gnu.org/copyleft/gpl.html
  42.  * @version CVS:$Id:
  43.  * @package lodel/install
  44.  */
  45.  
  46.  
  47. /**
  48.  *
  49.  * Remplacement de contenu dans un fichier suivant deux expressions : debut et fin.
  50.  *
  51.  *
  52.  * @param string $filename le nom du fichier dans lequel on doit faire le remplacement
  53.  * @param string $beginre l'expression permettant de trouver le début du remplacement
  54.  * @param string $endre l'expression permettant de trouver la fin du remplacement
  55.  * @param string $contents le contenu que l'on va insérer
  56.  */
  57. function replaceInFile($filename$beginre$endre$contents)
  58. {
  59.     if (!file_exists($filename)) {
  60.         return false;
  61.     }
  62.     $file file_get_contents($filename);
  63.     if (!$file)    die("probleme avec le fichier $filename");
  64.  
  65.     if (!preg_match("/$beginre/"$file)) {
  66.         die("impossible de trouver les begin pour publicfields dans $filename");
  67.     }
  68.     if (!preg_match("/$endre/"$file)) {
  69.         die("impossible de trouver les end pour publicfields dans $filename");
  70.     }
  71.  
  72.   $file preg_replace("/($beginre\n?).*?(\n?$endre)/s""\\1"$contents"\\2"$file);
  73.   $fp fopen($filename'w');
  74.   fwrite($fp$file);
  75.   fclose($fp);
  76.   return true;
  77. }
  78. ?>

Documentation generated on Thu, 19 Jun 2008 05:07:48 +0200 by phpDocumentor 1.4.0a2