Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i print my string as text and not HTML 1

Status
Not open for further replies.

jimberger

Programmer
Jul 5, 2001
222
GB
Hi,

I have a perl cgi web page. i also have a text file containing varibales such as

$test1='hello';
$test2='jim';

in my perl cgi page i require this text file

require "textfile.txt"

and then i can output the contents of the file as i now have access to the variables contained within the file..

so i can print "$test1" -- which will output hello to the screen..this works fine the problem occurs when the variable contains html code

e.g

$test3 = "this is just a test <b> help me </b> please";

when i print this to screen i will get help me in bold - which isnt what i want i actually want the <b> </b> to be outputted to screen - the browser is executing the HTML code when i just want to print it to screen.. has anyone got any ideas how i can do this?

thanks for your time
 
wrap your output in <pre> </pre> tags

HTH
--Paul

cigless ...
 
<pre> tags actually ignore any other enclosed html tags? I thought it was just a tool for preformmated whitespace, ala the "white-space: pre" in css.

To output <b>test</b> as characters and not rendered html, you need to encode the characters that make html think it's something different. The good solutions in modules are HTML::Entity's encode_entities() and CGI's escapeHTML(), but a simple solution that works most of the time would just be to encode the <
Code:
$test =~ s/</&lt;/g;
print $test;

________________________________________
Andrew

I work for a gift card company!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top