2 /************************************************************************
3 * MXChange v0.2.1 Start: 09/11/2008 *
4 * =============== Last change: 09/11/2008 *
6 * -------------------------------------------------------------------- *
7 * File : tpl-validator.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Only validates templates for correctness *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Validiert Templates auf korrektes HTML *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 if ($_SERVER['argc'] < 2) {
35 echo "Usage: ".basename(__FILE__)." <template> [--write]\n\n";
36 echo "Validates a template against the DOM model. Use --write with caution!\n";
40 $doc = new DOMDocument();
41 $doc->formatOutput = true;
42 $doc->preserveWhiteSpace = false;
43 $doc->encoding = "utf-8";
44 $doc->xmlVersion = "1.1";
45 $doc->loadHTMLFile($_SERVER['argv'][1]);
47 $data = $doc->saveHTML();
48 $data = str_replace("<br>", "<br />\n", $data);
49 $data = str_replace("\n\n", "\n", $data);
51 $array = explode("\n", $data);
54 unset($array[count($array) - 1]);
55 unset($array[count($array) - 1]);
57 $data = implode("\n", $array)."\n";
59 if (strtolower($_SERVER['arv'][2]) == "--write") {
60 echo "Writing document...\n";
61 file_put_contents($_SERVER['argv'][1], $data);