Jump to content

Display as text, yet don't execute?


Sniffy

Recommended Posts

I was wondering how to display a piece of html code as text on an html page yet don't execute it like in the w3schools tutorials.Would I use PHP or something and display my code as a variable and execute an echo like this?:

<html><head><title>Test Page of Mine</title></head><body><?php $MyTest="<html><head><title>test</title></head><body>This is a basic html document.</body></html>"echo  $MyTest ."That is an example of basic html" ?></body></html>

Link to comment
Share on other sites

If you are using PHP, you can use a built-in function.
<?php $MyTest="<html><head><title>test</title></head><body>This is a basic html document.</body></html>";echo htmlentities($MyTest);?>

http://www.php.net/manual/en/function.htmlentities.php

Your knowledge of php is impressively endless :) How long have you been involved with it :)
Link to comment
Share on other sites

I think I've worked with PHP for around 3 years now, maybe a little more. But most of the tips are give are because I've run into the same thing. I can't tell you how many times I've tried to write my own function to do a certain task (like convert HTML characters to entity codes), and then realize that there is a built-in function to do exactly that. That's the great thing about PHP, since it's open source and maintained by people that actually use it, there are a lot of time-saving things built-in that web programmers commonly use.But I wouldn't say my knowledge is endless. If I had to guess, I would say I've probably been exposed to around 30% of what PHP has to offer, and out of that 30%, probably about 40-50% I can use without needing to lookup online. The rest of the time I'm researching.It's not necessary to know everything, as long as you know where to look.

Link to comment
Share on other sites

Thanks fellow Nova Scotian. I would never have guest to use that code list of letters/ symbols.And thank you to the rest for contributing your knowledge. :)

no problem, but justsomeguy's solution would be far easier. Anytime I want ot display something that is a reserver char or something I resort to ASCII codes.
Link to comment
Share on other sites

And a wonderful place to look for is http://www.php.net/I see that justsomeguy always links to www.php.net when posting php functions. I bet he also thinks php.net is one of the best places to learn PHP. There always are examples on how to use functions.
By definition, nothing will ever be a better PHP resource than php.net. It's a little bit technical, but it's very informative. The user comments are also helpful. It's the first place I look for questions about PHP, and my second choice is generally a book.
Link to comment
Share on other sites

By definition, nothing will ever be a better PHP resource than php.net.  It's a little bit technical, but it's very informative.  The user comments are also helpful.  It's the first place I look for questions about PHP, and my second choice is generally a book.

Well, I'll keep it in mind. I'm getting better than PHP by the minute.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...