note 48131 added to function.htmlentities

From: Date: Mon, 13 Dec 2004 12:17:30 +0000
Subject: note 48131 added to function.htmlentities
Groups: php.notes 
Request: Send a blank email to php-notes+get-81743@lists.php.net to get a copy of this message
a function to encode everything but html tags. pattern improvement is much appreciated! function htmlEncodeText ($string) { $pattern = '<([a-zA-Z0-9\. "\'_\/-=;\(\)?&#%]+)>'; preg_match_all ('/' . $pattern . '/', $string, $tagMatches, PREG_SET_ORDER); $textMatches = preg_split ('/' . $pattern . '/', $string); foreach ($textMatches as $key => $value) { $textMatches [$key] = htmlentities ($value); } for ($i = 0; $i < count ($textMatches); $i ++) { $textMatches [$i] = $textMatches [$i] . $tagMatches [$i] [0]; } return implode ($textMatches); } ---- Manual Page -- http://www.php.net/manual/en/function.htmlentities.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48131 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48131&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48131&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81743) next »