note 42511 added to function.htmlentities
| From: | mail at britlinks dot com | Date: | Wed, 19 May 2004 13:27:31 +0000 |
| Subject: | note 42511 added to function.htmlentities | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-69825@lists.php.net to get a copy of this message | ||
similar to cedric at shift-zone dot be's function, this 'cleans up' text from MS
Word, and other non-alphanumeric characters to their valid [X]HTML counterparts
<?php
// strips slashes, and converts special characters to HTML equivalents for string defined in $var
function htmlfriendly($var,$nl2br = false){
$chars = array(
128 => '€',
130 => '‚',
131 => 'ƒ',
132 => '„',
133 => '…',
134 => '†',
135 => '‡',
136 => 'ˆ',
137 => '‰',
138 => 'Š',
139 => '‹',
140 => 'Œ',
142 => 'Ž',
145 => '‘',
146 => '’',
147 => '“',
148 => '”',
149 => '•',
150 => '–',
151 => '—',
152 => '˜',
153 => '™',
154 => 'š',
155 => '›',
156 => 'œ',
158 => 'ž',
159 => 'Ÿ');
$var = str_replace(array_map('chr', array_keys($chars)), $chars,
htmlentities(stripslashes($var)));
if($nl2br){
return nl2br($var);
} else {
return $var;
}
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.htmlentities.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42511
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42511&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42511&report=yes
Search -- http://master.php.net/manage/user-notes.php