///////////////////////////////////////////////////////////////////////////////////////
//HTML ENTITIES FUNCTIONS
///////////////////////////////////////////////////////////////////////////////////////
function CleanupSmartQuotes($text_nl) {
/*htmlentites is a very handy function, but it fails to fix one thing which I deal with alot:
word 'smart' quotes and emdashes.
The below function replaces the funky double quotes with ", funky single quotes with
standard single quotes and fixes emdashes.
*/
$badwordchars=array(
chr(145),
chr(146),
chr(147),
chr(148),
chr(151)
);
$fixedwordchars=array(
"'",
"'",
'"',
'"',
'—'
);
$text_nl = str_replace($badwordchars,$fixedwordchars,$text_nl);
return $text_nl;
}
function encodeText($text_nl) {
//This is a simple script that I'm using to encode and decode values from a form.
//Save it with the name that you wish.
/* When you call anyone of the two functions, set the $_str
variable to the string that you want to encode or decode */
/* This function encodes the string.
You can safetly use this function to save its result in a
database. It eliminates any space in the beginning ou end
of the string, HTML and PHP tags, and encode any special
char to the usual HTML entities (&[...];), eliminating the
possibility of bugs in inserting data on a table */
echo 'encodeText';
$text_nl = strip_tags($text_nl);
$text_nl = trim($text_nl);
$text_nl = htmlentities($text_nl);
$text_nl = str_replace("\r\n", "#BR#", $text_nl);
return $text_nl;
}
/* This function decodes the string.
If you are showing the string in the body of a page, you
can set the $_form variable to "false", and the function will
use the "BR" tag to the new lines. But, if you need to show
the string in a textarea, text or other input types of a form
set the $_form variable to "true", then the function will use
the "\r\n" to the new lines */
function decodeText($text_nl) {
$trans_tbl = get_html_translation_table (HTML_ENTITIES);
$trans_tbl = array_flip ($trans_tbl);
$text_nl = strtr($text_nl, $trans_tbl);
if ($_form) {
$_nl = "\r\n";
} else {
$_nl = "
";
}
$text_nl = str_replace("#BR#", "$_nl", $text_nl);
return($text_nl);
}
?>
Voorstellingen | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||