benwiggy
asked on
<xmp> equivalent
<pre> will not display the HTML code - how can i display HTML code without using the <xmp> tag or a textarea?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Interesting solution Batalf, but I think I will use the less than greater than signs I ended up using anyway.
But the Javascript one is interesting...
But the Javascript one is interesting...
Glad I could help!
The javascript solution is especially useful if you have alot of text and don't have access to use server side scripts for the conversion(< to < ).
Batalf
The javascript solution is especially useful if you have alot of text and don't have access to use server side scripts for the conversion(< to < ).
Batalf
ASKER
If you notice this, an example of a PHP server side solution?
There are several PHP solutions.
If the content is in a string you could just use str_replace() on it
example:
<?
$string = "<h1>This is a heading</h1><p>This is a paragraph</p>";
$string = str_replace("<","<",$st ring);
echo $string);
?>
You can also use the buffer functions. This means that you collect the buffer and don't output anything to the screen. Then you collect the content of the buffer and save it as a variable.
Example:
<?php
ob_start(); // Start output buffering
?>
<h1>This is a heading</h1>
<p>THis is a paragraph</p>
<p>This is also a paragraph</p>
<?
$data = ob_get_contents(); // Put the content of the buffer into the variable $data
ob_end_clean(); // Clean the buffer without outputting anything
$data = str_replace("<","<",$da ta); // replace < with <
echo $data;
?>
If the content is in a string you could just use str_replace() on it
example:
<?
$string = "<h1>This is a heading</h1><p>This is a paragraph</p>";
$string = str_replace("<","<",$st
echo $string);
?>
You can also use the buffer functions. This means that you collect the buffer and don't output anything to the screen. Then you collect the content of the buffer and save it as a variable.
Example:
<?php
ob_start(); // Start output buffering
?>
<h1>This is a heading</h1>
<p>THis is a paragraph</p>
<p>This is also a paragraph</p>
<?
$data = ob_get_contents(); // Put the content of the buffer into the variable $data
ob_end_clean(); // Clean the buffer without outputting anything
$data = str_replace("<","<",$da
echo $data;
?>
<pre><b>Bold text</b></pre>
...Returns bold text, and you want it to return literal "<>"s? If so, use this:
<pre><b>Bold text</b></pre>