Location: PHPKode > projects > Template Parser Engine > validator.php
<?php
// $Id: validator.php,v 1.1 2004/11/21 10:06:45 ellguth Exp ellguth $
//
// Info: To validate a page, include this PHP file in your code.
# if($_REQUEST['validated'] != 1) include("validator.php");


$validator = "http://validator.w3.org/check?uri=";
$uri = "";
$border = "0";

$valid = false;
$output = false;

// Set the URI now
if(!$uri)
 $uri = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];

if(strstr($uri, "?"))
 $uri.="&validated=1";
else
 $uri.="?validated=1";

echo $validator.urlencode($uri)."<br />";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($validator.urlencode($uri), "r"))) {
 die(sprintf("Can't parse ".$validator.urlencode($uri)));
 }

while (!feof ($fp)) {
 $data.= fgets($fp, 4096);
 }
if (!xml_parse($xml_parser, $data, feof($fp))) {
 die(sprintf("XML error: %s at line %d",
	     xml_error_string(xml_get_error_code($xml_parser)),
	     xml_get_current_line_number($xml_parser)));
 }

xml_parser_free($xml_parser);
fclose($fp);

function startElement($parser, $name, $attrs) {
 global $depth;
 global $valid;
 global $output;

 if($attrs['ID'] == "result" && $attrs['CLASS'] == "valid")
  $valid = true;

 if(strtoupper($name) == "PRE" && $valid == true) {
  $output = true;
 }

 if($output == true && strtoupper($name) == "P")
  $output = false;

 $depth[$parser]++;
}

function endElement($parser, $name) {
 global $depth;

 $depth[$parser]--;
}

function characterData($parser, $data) {
 global $uri;
 global $output;

 if($output == true) {
  $data = str_replace("img", "img border=\"".$border."\" ", $data);
  echo($data);
 }
}
?>
Return current item: Template Parser Engine