note 46698 added to function.htmlentities

From: Date: Wed, 20 Oct 2004 15:43:58 +0000
Subject: note 46698 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-78837@lists.php.net to get a copy of this message
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. <?php /* 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 */ function encodeText($_str) { $_str = strip_tags($_str); $_str = trim($_str); $_str = htmlentities($_str); $_str = str_replace("\r\n", "#BR#", $_str); return($_str); } /* 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($_str, $_form) { $trans_tbl = get_html_translation_table (HTML_ENTITIES); $trans_tbl = array_flip ($trans_tbl); $_str = strtr($_str, $trans_tbl); if ($_form) { $_nl = "\r\n"; } else { $_nl = "<br>"; } $_str = str_replace("#BR#", "$_nl", $_str); return($_str); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+46698 Delete -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46698&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+46698&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#78837) next »