php code view like a text?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

php code view like a text?

Post by jayson.ph »

Hi all, how to post an php code or html code that can view like text?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php code view like a text?

Post by twinedev »

save a copy adding .txt to the end of the file.... myscript.php => myscript.php.txt

Or do you mean set it so that any .php in a certain directory (.ie and uploads directory where people can upload files) does not execute (I have seen sites get hacked this way).

If so, then add something like the following into an .htaccess file in that directory:

Code: Select all

AddType text/plain .pl .cgi .php
Be sure to add all variations that work on your server.... (.php, .php4, .php5, .phtml etc)

-Greg
User avatar
jayson.ph
Forum Contributor
Posts: 165
Joined: Mon Jan 02, 2012 9:20 am
Location: MP
Contact:

Re: php code view like a text?

Post by jayson.ph »

i mean is, i want to post a php code in a website, like a tutorial. when the visitor open the website he/she can see actually the code tutorial. like this website. http://www.w3schools.com/php/php_mail.asp
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: php code view like a text?

Post by twinedev »

All you have to do is use the correct entities (see http://www.w3schools.com/html/html_entities.asp) on the code and the either style a div to hold it, or wrap with <pre><tt> </tt></pre> to have ti be fixed width and keep all spacing.
Post Reply