1

Topic: Display php-code?

How have you done for displaying php-code in the posts, instead of running it?

I have that problem in my articles.

Please tell me! smile

Re: Display php-code?

I'm not sure I understand what you mean. If you just output PHP code it won't run:

echo '<?php echo "bajs" ?>';

will not print out bajs. It will print out

<?php echo "bajs" ?>

Am I missing something?

"Programming is like sex: one mistake and you have to support it for the rest of your life."

3 (edited by Woppe 2003-09-05 15:20)

Re: Display php-code?

"bajs" is not a nice word! wink

I'll test what you just wrote. I really hope that it is not that easy! smile

4

Re: Display php-code?

for me displayes

echo "<? echo \"test\"; ?>";

nothing.

What's wrong..?? :confused:

Re: Display php-code?

What is the problem? I think you have to tell me a little more about what you want to do.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

6

Re: Display php-code?

I have text (and sometimes php-code) in a database.
I want to display the text and code, not run it.

Do you understand?

If I write:
echo "hej";
it displays "hej".

But if i write echo "<? echo\"hej\"; ?>";
it doesn't display <? echo "hej"; ?> it displays nothing!

Do you have any idea of what can be wrong?

Thank you!

Re: Display php-code?

Try running htmlspecialchars() on the text before outputting it.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

8

Re: Display php-code?

Ah, now everything is displayed in text. Even the <br>'s. How can I get around that?

Re: Display php-code?

try running htmlspecialchars(str_replace("<br>", "\n", $text)) or something?

Re: Display php-code?

Well, you have to run htmlspecialchars() on the text before you convert \n to <br>.

"Programming is like sex: one mistake and you have to support it for the rest of your life."

11

Re: Display php-code?

Now I got it right!
I used:

get_article = stripslashes($article->get_text());
$get_article = htmlspecialchars($get_article);
echo nl2br($get_article);

Thanks guys!