Jump to content
xisto Community
Sign in to follow this  
matak

How To Display Php Code [resolved] Html Help With Php Codebox

Recommended Posts

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 worksIf 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

Edited by jlhaslip
resolved, per member request (see edit history)

Share this post


Link to post
Share on other sites

Use the PHP function "htmlentities" to convert everything placed inside the CODEBOX bbcode. That should do it.

Share this post


Link to post
Share on other sites

What happens if you use the <pre> tags but do not include the php start and end tags?

<pre><!-- -some php code here -->echo 'this';echo 'and that ';<!-- -end php code here --></pre>

Share this post


Link to post
Share on other sites

I found this way..

<?php$mycode = '<?php echo("hello");?> <html>';$stvarno = array ("<", ">");$zamjenjeno = array ("<",">");$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..
Edited by matak (see edit history)

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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. ;)

Share this post


Link to post
Share on other sites

topic title modified as per thread author's request. ;)

thank you dear moderator ;) 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..

<?php$mycode = '<?php echo("hello");?> [b]<html>[/b]';$stvarno = array ("<", ">", "[b]", "[/b]");$zamjenjeno = array ("<",">", "<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

Share this post


Link to post
Share on other sites

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

@truefusioni 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..

<?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.

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:
$mycode = '[b]<[/b]?php echo("hello");?[b]>[/b] [b]<html>[/b]';

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.