Displaying php code in a php page

danielneridanielneri WP V.I.P.VPS - Virtual Prince of the Server
I have a script which pulls articles from a database, but some of the articles have php code in them that i want to DISPLAY rather than EXECUTE

does anybody have any ideas?
ban1.gif

Comments

  • pfgannonpfgannon Moderator Administrator
    heh that sucks.

    I've read on how to solve this but I can't say that I remember how to do it.
    Sorry:(
  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    If you're not planning on using PHP's inbuilt PHP code highlighter, it's as simple as:
    [PHP]<?php
    $variable = "This is the code:
    <?php echo 'code'; ?>";
    $variable = str_replace("<", "<", $variable);
    $variable = str_replace(">",">", $variable);
    ?>[/PHP]
    If you plan to use PHP's highlighter, it's a bit different, but the highlighter isn't much good unless you don't mind not being able to easily highlight other languages (it only works on PHP by default).
    The basic jist of it is that HTML is designed so that code won't get rendered as anything other than text unless it's HTML tags or CSS, ASCII character codes or a few other things.
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    but im using it in a database....

    http://www.vipercreations.com/tutorials.php?phpID=3


    help?!


    thats okay fourtone :)
    ban1.gif
  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    X_X
    Get the contents you want from your DB and store it in a variable so you can work on it before echoing it to the output.
    Ideally, you should do this before inserting the article into the database since it will add to the loading time if you do it each time the end user load the article (it also adds to server load).
    If you do it before insertion, you only increase server load and loading times when you insert articles and when you edit them (because you have to convert the tags and such).
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    so could you help me out here? i right now have no flying clue what to do!
    ban1.gif
  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    You know when you insert an article into the DB?
    Before inserting it with the mysql query, you'd want to use the code I posted above to change:
    [php]
    mysql_query("INSERT blah blah");
    [/php]

    to:
    [php]
    $article = $_GET;
    $article = str_replace("<","<",$article);
    $article = str_replace(">",">",$article);

    mysql_query("INSERT blah blah but using the modified body of the article");
    [/php]

    I have a very lame script which enables highlighted PHP code blocks, but due to the way it's built, posting it here is a bit funky (it uses the [ php ] tags vB also uses, thus causing problems when written here).
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    I have a very lame script which enables highlighted PHP code blocks, but due to the way it's built, posting it here is a bit funky (it uses the [ php ] tags vB also uses, thus causing problems when written here).


    can you post a text file?

    btw thanks alot ill check the script out
    ban1.gif
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    wow nuvo thanks so much you are by far one of the most helpful members of this forum!!!
    ban1.gif
  • PythonPython Forum Leader The Royal RAM
    ^^ I agree there :)
    Thats the sort of person who makes moderator status ;)

    The Royal Ram

  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    so make him a moderator! he has been deserving it for months!!!!
    ban1.gif
  • NuvoNuvo Forum Leader VPS - Virtual Prince of the Server
    O_o
    Anyway, I'm in the process of rewriting a BBCode parser which should be useful for getting people started with writing such things.
    I'll do that (shouldn't take long) and post it here.
    It should have the PHP highlighting code in with it.
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!
  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    alright cool

    python make him a moderator now!
    ban1.gif
  • PythonPython Forum Leader The Royal RAM
    lol... :D

    I will look into it more when christmas is out of the way... Thats when I plan to make some changes around here ;)

    The Royal Ram

  • danielneridanielneri WP V.I.P. VPS - Virtual Prince of the Server
    nice...
    ban1.gif
Sign In or Register to comment.