note 42511 added to function.htmlentities

From: 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 => '&#8364;', 130 => '&#8218;', 131 => '&#402;', 132 => '&#8222;', 133 => '&#8230;', 134 => '&#8224;', 135 => '&#8225;', 136 => '&#710;', 137 => '&#8240;', 138 => '&#352;', 139 => '&#8249;', 140 => '&#338;', 142 => '&#381;', 145 => '&#8216;', 146 => '&#8217;', 147 => '&#8220;', 148 => '&#8221;', 149 => '&#8226;', 150 => '&#8211;', 151 => '&#8212;', 152 => '&#732;', 153 => '&#8482;', 154 => '&#353;', 155 => '&#8250;', 156 => '&#339;', 158 => '&#382;', 159 => '&#376;'); $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

« previous php.notes (#69825) next »