<?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> 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> 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> 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	how about a <span style="color: red"  title="You & Me:  lip to lip"
	onmouseover=
'this.style.color="pink"'
onclick="alert('¡smoochy smoochy smack!')">Fat &#x22;Kiss&#x22;</span> to  >make /my\ day<  <special>.
   <a href="javascript: alert('hello');">&iexcl;click me!</a>
<pre>
Roses are red
Violets are blue ('round hea theyz kinda purple)
Sugar is 	SO…… sweet
•And so are →⇒you⇐←
</pre>
Hidden space here: > < will show up when Control Chars are stripped.
This is my ™trademark© function.
<?php } ?></textarea><br />
<label>nl to <br /> <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>
<label>TRUE<input type='radio' name='spaces' value='TRUE' /></label>
<label>FALSE<input type='radio' name='spaces' value='FALSE' /></label>
</fieldset><br />
<fieldset>
<label>HTML<input type='radio' name='xhtml' value='html' /></label>
<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>
<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>
<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>&nbsp;</option>
<option>&#160;</option>
<option>&#32;</option>
<option>&#8194;</option>
<option>&ensp;</option>
<option>&#8195;</option>
<option>&emsp;</option>
<option>&#8201;</option>
<option>&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 "official" 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=> '$ent'$tab&$ent;\n";}
// echo htmlentities(var_export(RegulateText::get_entities())); ?>
)
</pre>
<h2>
</body>
</html>
|