note 47220 added to function.htmlspecialchars
| From: | programmabilities dot com at osu1 dot php dot net | Date: | Sun, 07 Nov 2004 02:59:44 +0000 |
| Subject: | note 47220 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80206@lists.php.net to get a copy of this message | ||
I tried to use htmlspecialchars() to render/display my script code on a page but it would process
the $variable's, so it wouldn't work. Actually, there is another way, which may be even
simpler.
For a long time, the HTML language has provided the <xmp> tag for showing, well, examples of
mark-up and programs in the <html> and <script> tags which would otherwise be rendered.
Thus, all you really need to do is wrap your mark-up in xmp tags <xmp>like this - <a
href="whatever">this link will not be a link</a> ;)</xmp>, and the browsers
will show it verbatim instead of rendering it. And yes, this works for scripts, too - no
self-respecting browser should ever execute any <script> code when it is within an xmp block.
So to display your PHP code, instead of the <?php ?> tag, put it in the <script
type="php"> tag.
--Of course, wrapping <?php ...?> in 'xmp' tags will not display it literally, since
'xmp' is processed by the client. The server will still happily execute the code and then
pass its output within the 'xmp' tags... not exactly the purpose of the whole exercise.
--SO, put your PHP code in the <script type="php"> tag!
Otherwise, 'xmp' always works just fine for client-side mark-up and code like HTML and
JavaScript.
By Chief Programmabilities at http://programmabilities.com
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47220
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47220&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47220&report=yes
Search -- http://master.php.net/manage/user-notes.php