note 61249 added to function.preg-replace
| From: | Marcus at osu1 dot php dot net | Date: | Sun, 29 Jan 2006 13:12:11 +0000 |
| Subject: | note 61249 added to function.preg-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102666@lists.php.net to get a copy of this message | ||
To display all code within 2 tags (even custom ones) to the user, you can use the following:
<?php
$text = preg_replace("/<code>(.*)<\/code>/e"
,'"<code>".htmlspecialchars("$1")."</code>"' ,
$text);
?>
Here it will convert all characters within the "<code>" tags to entities that the
user will see rather than have it formated by the browser. Useful for displaying code in articles
etc.
- http://www.marcusnoble.co.uk
----
Server IP: 85.116.0.130
Probable Submitter: 84.92.153.231
----
Manual Page -- http://www.php.net/manual/en/function.preg-replace.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61249
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61249&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61249&report=yes
Search -- http://master.php.net/manage/user-notes.php