PHP Classes

File: test_XHTMLencode.php

Recommend this page to a friend!
  Classes of Joseph  >  Regulate XHTML Text  >  test_XHTMLencode.php  >  Download  
File: test_XHTMLencode.php
Role: Example script
Content type: text/plain
Description: Demo of Regulate Text Class (XHTMLencode)
Class: Regulate XHTML Text
Encode characters in text in HTML tags
Author: By
Last change:
Date: 11 years ago
Size: 7,208 bytes


Class file image Download
<?php /* test_XHTMLencode.php written by and Copyright 2009,2010 Joe Golembieski, SoftMoon WebWare

        This program is free software: you can redistribute it and/or modify
        it under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.

        This program is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        GNU General Public License for more details.

        You should have received a copy of the GNU General Public License
        along with this program. If not, see <> /*/

// source code formatting:
// tab spacing=2 line-width=120 chars word-wrap=NO

require "PHP_Functions.php";

unslash($posted) {
    if (
get_magic_quotes_gpc()) {
        if (empty(
$mqs) or $mqs=='off') $posted=stripslashes($posted);
$posted=str_replace("''", "'", $posted); }
$posted; }
body {color: lime; background-color: black;}
div {border: 2px solid orange; margin: 0 50% 2em 0; display: inline-block; color: orange;}
div u {color: lime;}
a {color: blue; background-color: black;}
a:visited {color: blue; background-color: black;}
a:hover {color: orange; background-color: black;}
textarea {color: aqua; background-color: black;}
select, input {color: yellow; background-color: black;}
fieldset {display: inline-block;}
if (isset($_POST['userSays']))
"<div><u>",$_POST['userSays'],"</u> &nbsp; raw length=",strlen($_POST['userSays']),"</div>\n",
"<div><u>Magic_Quotes_GPC</u> =",get_magic_quotes_gpc(),"<br />\n",
"<u>Magic_Quotes_Sybase</u> =",ini_get('magic_quotes_sybase'),"</div>\n",
"<div><u>",$_POST['userSays']=unslash($_POST['userSays']),"</u> &nbsp; unslashed length=",strlen($_POST['userSays']),"</div>\n",
$_POST['spaces']=='Ents') ? "toEntities" : (($_POST['spaces']=='TRUE') ? TRUE : FALSE),
$_POST['alignEnts']=='FALSE') ? FALSE : $_POST['alignEnts'],
$_POST['transform_nonstandard_Ents']=='FALSE') ? FALSE : $_POST['transform_nonstandard_Ents'],
$_POST['hardspace_userdef'] ? $_POST['hardspace_userdef'] : $_POST['hardspace']) ),
"</u> &nbsp; encoded length=",strlen($_POST['userSays']),"</div>\n",
"<h3>Try viewing the HTML sourcecode of this page to further understand the process</h3>";
<form action="test_XHTMLencode.php" method='post'>
<textarea name='userSays' cols='62' rows='13'><?php if (isset($_POST['userSays'])) echo htmlentities($_POST['userSays'], ENT_QUOTES);
else {
?>beyond that&#09;how about a &lt;span style=&quot;color: red&quot;&#32; title=&quot;You &amp; Me:&#32; lip to lip&quot;
onclick=&quot;alert('&iexcl;smoochy smoochy smack!')&quot;&gt;Fat &amp;#x22;Kiss&amp;#x22;&lt;/span&gt; to &#32;&gt;make /my\ day&lt;&#32; &lt;special&gt;.
&#32; &#32;&lt;a href=&quot;javascript: alert('hello');&quot;&gt;&amp;iexcl;click me!&lt;/a&gt;

Roses are red
     Violets are blue ('round hea theyz kinda purple)
Sugar is &#13;&#09;SO&#8230;&#8230; sweet
&bull;And so are &rarr;&rArr;you&lArr;&larr;
Hidden space here: &#62; &#08;&#60; will show up when Control Chars are stripped.

This is my &trade;trademark&copy; function.
<?php } ?></textarea><br />

<label>nl to &#60;br /&#62; <input type='checkbox' name='nl_to_br' value='TRUE' checked='checked' /></label><br />

<label>allow JavaScript <input type='checkbox' name='allowJS' value='TRUE' checked='checked' /></label><br />

<fieldset><legend>modulate spaces</legend>
<label>toEntities<input type='radio' name='spaces' value='Ents' checked='checked' /></label>&nbsp;
<label>TRUE<input type='radio' name='spaces' value='TRUE' /></label>&nbsp;
<label>FALSE<input type='radio' name='spaces' value='FALSE' /></label>
</fieldset><br />

<label>HTML<input type='radio' name='xhtml' value='html' /></label>&nbsp;
<label>XHTML<input type='radio' name='xhtml' value='xhtml' checked='checked' /></label>
</fieldset><br />

<fieldset><legend>character set</legend>
<select name='charset'>
</select></fieldset><br />

<fieldset><legend>retain formatting</legend>
<label>TRUE<input type='radio' name='retain' value='TRUE' checked='checked' /></label>&nbsp;
<label>FALSE<input type='radio' name='retain' value='FALSE' /></label>

<fieldset><legend>strip Control Characters</legend>
<label>TRUE<input type='radio' name='strip' value='TRUE' checked='checked' /></label>&nbsp;
<label>FALSE<input type='radio' name='strip' value='FALSE' /></label>
</fieldset><br />

<fieldset><legend>align Ents</legend>
<select name='alignEnts'>

<fieldset><legend>transform Nonstandard Ents</legend>
<select name='transform_nonstandard_Ents'>
</select></fieldset><br />

<fieldset><legend>tab spacing</legend>
<input type='text' name='tabSp' value='8' maxlength='2' size='2' /></fieldset>

<select name='hardspace'>
<input type='text' name='hardspace_userdef' value='' maxlength='10' size='10' /></fieldset>

<input type='submit' name='submit' />
</form><br />
<a href="test_XHTMLencode.php">Reset form to initial test string</a>

<h2>here is PHP's &#34;official&#34; HTML entities table:</h2>
<?php echo htmlentities(var_export(get_html_translation_table(HTML_ENTITIES), TRUE)); ?>
<h2>here is our HTML entities table, also showing if your browser supports each entity:</h2>
<?php $ents=RegulateText::get_entities(); $tab=chr(9);
    foreach (
$ents as $code => $ent) {echo " $code$tab=&gt; '$ent'$tab&$ent;\n";}
// echo htmlentities(var_export(RegulateText::get_entities())); ?>

For more information send a message to info at phpclasses dot org.