Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-06-2012, 02:34 PM   PM User | #1
verhoeven03
New to the CF scene

 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
verhoeven03 is an unknown quantity at this point
Show PHP as text in a forum

I would like to show PHP and HTML code in a forum. Therefore I must display the code as plain text. But everytime the website executes the PHP code and won't display it.

I have seen PHP code boxes around on websites, these can also work for me.

For example, i want to show the following code as plain tekst:
[button link="#"] Button Text [/button]

Can anyone help me please?

Thanks
verhoeven03 is offline   Reply With Quote
Old 01-06-2012, 02:47 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If the PHP is executing, you haven't specified that it is a string. Whether it is a string or comes from a database, the only way to execute it beyond the scope of the immediate script is with an eval. So the first step will be making it into an actual string.
To display the string, it is the same as displaying HTML. Use htmlspecialchars() in order to convert the tags so that it can be displayed without a parse.
Fou-Lu is offline   Reply With Quote
Old 01-06-2012, 03:37 PM   PM User | #3
verhoeven03
New to the CF scene

 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
verhoeven03 is an unknown quantity at this point
Thanks for the reply, I do not understand it completely.

Is there no code like <textbox> PHP Code </textbox> which I can add while composing the new thread so that the code is displayed?
verhoeven03 is offline   Reply With Quote
Old 01-06-2012, 03:39 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,521
Thanks: 45
Thanked 440 Times in 429 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
You could do that yes but that won't stop php from running the php code - that will just determine how it looks on the clients browser.

Put the php code through htmlspecialchars() first as Fou has suggested. If the php is being executed on the server before printing it to the browser then you need to stop that from happening.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 01-06-2012, 03:41 PM   PM User | #5
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,662
Thanks: 4
Thanked 2,452 Times in 2,421 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Textarea is a html property. Your job is to make sure that anything between the textarea tags is readable as plain text. If you use something like HTML or PHP within the textarea, you have to replace the characters appropriately so that it can be displayed as text and not HTML.
PHP Code:
$string = '<?php echo "hello world";?>'; // <> indicates HTML tags if left in this format

printf('<textarea>%s</textarea>', htmlspecialchars($string));
The textarea should now render the PHP code as text and not an element.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
code, display, forum, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:56 AM.


Advertisement
Log in to turn off these ads.