Link to home
Start Free TrialLog in
Avatar of benwiggy
benwiggyFlag for United Kingdom of Great Britain and Northern Ireland

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
Avatar of Batalf
Batalf
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joakim_
Joakim_

Do you mean that this:

<pre><b>Bold text</b></pre>

...Returns bold text, and you want it to return literal "<>"s? If so, use this:

<pre>&lt;b&gt;Bold text&lt;/b&gt;</pre>
Avatar of benwiggy

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...
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 &lt; ).

Batalf

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("<","&lt;",$string);
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("<","&lt;",$data); // replace < with &lt;

echo $data;

?>