note 42511 deleted from function.htmlentities by hholzgra

From: Date: Thu, 02 Aug 2012 11:24:25 +0000
Subject: note 42511 deleted from function.htmlentities by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189586@lists.php.net to get a copy of this message
Note Submitter: mail at britlinks dot com ---- 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; } } ?>

« previous php.notes (#189586) next »