PHP Classes

File: good_bad_examples.php

Recommend this page to a friend!
  Classes of Patricio Cardó   Selector and Validator for XHTML parts   good_bad_examples.php   Download  
File: good_bad_examples.php
Role: Example script
Content type: text/plain
Description: Examples of validating strings of xhtml code parts
Class: Selector and Validator for XHTML parts
Parse HTML to validate it and extract parts
Author: By
Last change:
Date: 13 years ago
Size: 2,162 bytes
 

Contents

Class file image Download
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head><title>Good and Bad examples</title>
<style type='text/css'>
    p , h2{font-family:Verdana,sans-serif;margin-top:12px;margin-bottom:2px}
</style>
</head>
<body>
<h2>Good example</h2>
<p>The following part of xhtml code can be parsed without problems in a browser</p>
<?php
require("xhtml_parte_inc.php");
$source = "
    <tr><td>Cell A1</td><td>Cell B1</td></tr>
    <tr><td>Cell A2</td><td>Cell B2</td></tr>
    "
;
print
"<code>".nl2br(htmlentities($source))."</code>";
$myx = new xhtml_parte($source);
$ver = ($myx->validar())?"validated":"not validated";
print
"<p>That is why validation will be ok: code was ".$ver."</p>";

?>
<h2>Bad example 1</h2>
<p>The following part of xhtml code cannot be parsed well in a browser due to closed tag missings</p>
<?php
$source
= "
    <div><span>Fragment 1</span><span>Fragment 2
                            <div>Sub layer</span></div>
                            <a href='non'>algo
    "
;
print
"<code>".nl2br(htmlentities($source))."</code>";
$myx2 = new xhtml_parte($source);
$ver = ($myx2->validar())?"validated":"not validated";
print
"<p>That is why validation will be bad: code was ".$ver.". And causes will be:</p>";
print
"<ul><li>".implode("</li><li>",$myx2->log)."</li></ul>";

?>
<h2>Bad example 1</h2>
<p>The following part of xhtml code may be parsed in most browsers but has some mistakes</p>
<?php
$source
= "
    <style type='text/css'><[CDATA[
        .tip{font-size:small}
    ]]></style>
       
    <script type='text/javascript'>
        document.write('this is an example');
    </script>
    <a href='gotosomewhere.html'>link but <a name='anchor'> anchor here</a></a>
    <br>
    <p class=tip>This is a styled tip</p>
    <br />
    <p>This is a checkbox <input type='checkbox' id='chk1' checked /></p>
    "
;
print
"<code>".nl2br(htmlentities($source))."</code>";
$myx3 = new xhtml_parte($source);
$ver = ($myx3->validar())?"validated":"not validated";
print
"<p>That is why validation will be bad: code was ".$ver.". And causes will be:</p>";
print
"<ul><li>".implode("</li><li>",$myx3->log)."</li></ul>";

?>
</body>
</html>