Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How To Display Php Code [resolved], Html Help With Php Codebox
matak
post Jan 31 2007, 06:26 PM
Post #1


Super Member
*********

Group: Members
Posts: 412
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



I'm trying to make codebox for my guestbook so that users can post PHP code inside..
I tried many versions but none of them works

If i use <xpm>, <pre> or <textbox> i can display HTML code, but when i try to write PHP code it executes it does not display..
There is a way to make swap for <? with ANSCI characters but that is not convenient for me.

You have codebox in forum to display php how can i make that?!
thanks

This post has been edited by jlhaslip: Jan 31 2007, 07:13 PM
Reason for edit: resolved, per member request
Go to the top of the page
 
+Quote Post
truefusion
post Jan 31 2007, 06:35 PM
Post #2


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,865
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



Use the PHP function "htmlentities" to convert everything placed inside the CODEBOX bbcode. That should do it.
Go to the top of the page
 
+Quote Post
jlhaslip
post Jan 31 2007, 06:40 PM
Post #3


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



What happens if you use the <pre> tags but do not include the php start and end tags?
CODE
<pre>
<!-- -some php code here -->

echo 'this';
echo 'and that ';

<!-- -end php code here -->
</pre>
Go to the top of the page
 
+Quote Post
matak
post Jan 31 2007, 06:51 PM
Post #4


Super Member
*********

Group: Members
Posts: 412
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



I found this way..

CODE
<?php

$mycode = '<?php echo("hello");?> <html>';

$stvarno = array ("<", ">");

$zamjenjeno = array ("&lt;","&gt;");

$code = str_replace($stvarno, $zamjenjeno, $mycode);

echo ("$code");

?>


now i need to find a way that my guestbook creates this $mycode string.. that's bothering me to, but i really didn't start on creating gbook yet. i hopet that's not gonna be problem..

@jlhaslip
in your code you dont use php start and end tags, when you use them it just echo's this and that

@truefusion
i don't know that command, and that, i'll probably use that later maybe for adding bbcode. if you can make simple example of how to use it it would be great..

This post has been edited by matak: Jan 31 2007, 06:55 PM
Go to the top of the page
 
+Quote Post
matak
post Jan 31 2007, 07:01 PM
Post #5


Super Member
*********

Group: Members
Posts: 412
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



i wanted to change topic to solved, couse this is really what i was looking for a long time. i guess i was lucky 10 minutes after posting, so if mods can change title to something like "How to display php code" it would be great. I tried editing but i guess it's not an option in new forum anymore...
Go to the top of the page
 
+Quote Post
serverph
post Jan 31 2007, 07:13 PM
Post #6


Ancient Enigma
Group Icon

Group: [MODERATOR]
Posts: 1,753
Joined: 11-July 04
From: under the stars
Member No.: 76



QUOTE(matak)
i wanted to change topic to solved, couse this is really what i was looking for a long time. i guess i was lucky 10 minutes after posting, so if mods can change title to something like "How to display php code" it would be great. I tried editing but i guess it's not an option in new forum anymore...


topic title modified as per thread author's request. smile.gif
Go to the top of the page
 
+Quote Post
matak
post Jan 31 2007, 07:48 PM
Post #7


Super Member
*********

Group: Members
Posts: 412
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



QUOTE(serverph @ Jan 31 2007, 08:13 PM) *
topic title modified as per thread author's request. smile.gif

thank you dear moderator biggrin.gif
i just wanted to add this little perk of code above..

if you want to add some html features to your codebox like bold do it like this..

CODE
<?php

$mycode = '<?php echo("hello");?> [b]<html>[/b]';

$stvarno = array ("<", ">", "[b]", "[/b]");

$zamjenjeno = array ("&lt;","&gt;", "<b>", "</b>");

$code = str_replace($stvarno, $zamjenjeno, $mycode);

echo ("$code");

?>


and voila, you can say that is BB(bulletin board) code
but for some reason it's not going to bold < and > characters.. dunno why
Go to the top of the page
 
+Quote Post
truefusion
post Feb 1 2007, 12:45 AM
Post #8


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,865
Joined: 22-June 05
From: The World of Gentoo
Member No.: 8,528
T17 GFX Crew



I know the problem is resolved, but i'll respond to these...

QUOTE(matak @ Jan 31 2007, 01:51 PM) *
@truefusion
i don't know that command, and that, i'll probably use that later maybe for adding bbcode. if you can make simple example of how to use it it would be great..

CODE
<?php

$mycode = '<?php echo("hello");?> <html>';
$mycode = htmlentities($mycode);

echo "<pre>".$mycode."</pre>";

?>

This is how i would have done it: less work, just as affective.

QUOTE(matak @ Jan 31 2007, 02:48 PM) *
but for some reason it's not going to bold < and > characters.. dunno why

Reason being 'cause the bbcodes don't surround the less-than and greater-than symbols, like so:
CODE
$mycode = '[b]<[/b]?php echo("hello");?[b]>[/b] [b]<html>[/b]';
Go to the top of the page
 
+Quote Post
matak
post Feb 1 2007, 01:47 AM
Post #9


Super Member
*********

Group: Members
Posts: 412
Joined: 4-October 06
From: Psychedelic Realms
Member No.: 31,079



thanks for the tip.. Really is much simpler.
I solved that issue with bolding < and > characters. It was kinda simple, all i had to do is add <pre> tag to echo.. like you did with htmlentities code it works just fine...