Login   Register  
PHP Classes
elePHPant
Icontem

File: test_XHTMLencode.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  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: 2011-06-17 11:14
Size: 7,208 bytes
 

Contents

Class file image Download
<?php  /*  test_XHTMLencode.php  written by and Copyright © 2009,2010 Joe Golembieski, SoftMoon WebWare
                        see:    http://softmoon-webware.com/php_functions-instructions.php/
                                        http://softmoon-webware.com/php_functions.zip/

        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
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        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 <http://www.gnu.org/licenses/>    /*/

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


require "PHP_Functions.php";


Function 
unslash($posted)  {
    if (
get_magic_quotes_gpc())  {
        
$mqs=strtolower(ini_get('magic_quotes_sybase'));
        if (empty(
$mqs)  or  $mqs=='off')  $posted=stripslashes($posted);
        else  
$posted=str_replace("''""'"$posted);  }
    return 
$posted;  }
?>
<html>
<head>
<title>test_XHTMLencode.php</title>
<style>
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;}
</style>
</head>
<body>
<?php
    
if (isset($_POST['userSays']))
        echo
    
"<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",
    
"<div><u>",$_POST['userSays']=RegulateText::XHTMLencode(
        
$_POST['userSays'],
        (
$_POST['nl_to_br']=='TRUE'),
        (
$_POST['allowJS']=='TRUE'),
        (
$_POST['spaces']=='Ents') ? "toEntities" : (($_POST['spaces']=='TRUE') ? TRUE FALSE),
        (
$_POST['xhtml']=='xhtml'),
        
$_POST['charset'],
        (
$_POST['retain']=='TRUE'),
        (
$_POST['strip']=='TRUE'),
        (
$_POST['alignEnts']=='FALSE') ? FALSE $_POST['alignEnts'],
        (
$_POST['transform_nonstandard_Ents']=='FALSE') ? FALSE :    $_POST['transform_nonstandard_Ents'],
        
$_POST['tabSp'],
        (
$_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;
&#09;onmouseover=
'this.style.color=&quot;pink&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;

&#60;pre&#62;
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;
&#60;/pre&#62;
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 />

<fieldset>
<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'>
<option>ISO-8859-1</option>
<option>ISO-8859-15</option>
<option>UTF-8</option>
<option>cp866</option>
<option>cp1251</option>
<option>cp1252</option>
<option>KOI8-R</option>
<option>BIG5</option>
<option>GB2312</option>
<option>BIG5-HKSCS</option>
<option>Shift_JIS</option>
<option>EUC-JP</option>
</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>

<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'>
<option>FALSE</option>
<option>numeric</option>
<option>mnemonic</option>
</select></fieldset>

<fieldset><legend>transform Nonstandard Ents</legend>
<select name='transform_nonstandard_Ents'>
<option>FALSE</option>
<option>numeric</option>
<option>mnemonic</option>
</select></fieldset><br />

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

<fieldset><legend>hardspace</legend>
<select name='hardspace'>
<option>&amp;nbsp;</option>
<option>&amp;#160;</option>
<option>&amp;#32;</option>
<option>&amp;#8194;</option>
<option>&amp;ensp;</option>
<option>&amp;#8195;</option>
<option>&amp;emsp;</option>
<option>&amp;#8201;</option>
<option>&amp;thinsp;</option>
</select>
<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>
<pre>
<?php echo htmlentities(var_export(get_html_translation_table(HTML_ENTITIES), TRUE)); ?>
</pre>
<h2>here is our HTML entities table, also showing if your browser supports each entity:</h2>
<pre>
  array(
<?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())); ?>
  )
</pre>
<h2>
</body>
</html>