SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Disabled PHP

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Disabled PHP

    is there a code at all to disable php, so i can use php codes on part of a page and it displays the code not actualy works?

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    $str= "<?php echo 'this and that ' ?>";
    echo htmlentities($str);
    Would that do it?

    If not adding <pre></pre> around the output might make it look more like code.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are three ways to store it so it doesn't execute. The first is as cups said, store it as a string. The second is by storing it in a text file. The third is by storing it in a mysql database.

    However, did you know that you could just put this on a webpage:
    PHP Code:
    &lt;? echo 'hello world'; ?&gt
    and because it's encoded like so, it doesn't think it's PHP.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Addict CVPer's Avatar
    Join Date
    Sep 2007
    Location
    Vancouver, BC, Canada
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    contents within <?php and ?> are considered php code and will be evaluated on the server, so you just need to change them to html code.
    for example, you have a php file (contents.php) and want to show it in another page (show.php)

    conents.php:
    PHP Code:
    <?php
    echo 'test of showing php code';
    ?>
    show.php:
    PHP Code:
    <?php
    $php_code 
    file_get_contents('conents.php');

    $php_code str_replace('?>''?&gt;'str_replace('<?''&lt;?'$php_code));

    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
      <title>show php code</title>
      </head>
      <body>
        
        <pre><?php echo $php_code?></pre>
        
      </body>
    </html>
    * @location Vancouver, BC, Canada
    * @name Steve
    * @job PHP/MySQL, Drupal, WordPress Developer

  5. #5
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    and, if you want to show the file in a color-formatted way:
    PHP Code:
    <p>This is how you would do blah:</p>
    <code><? highlight_file("blah.php"); ?></code>
    Oh, steve - I don't think you need to replace the PHP tags if you use file_get_contents - It's stored in a string variable.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  6. #6
    SitePoint Addict CVPer's Avatar
    Join Date
    Sep 2007
    Location
    Vancouver, BC, Canada
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arkinstall View Post
    and, if you want to show the file in a color-formatted way:
    PHP Code:
    <p>This is how you would do blah:</p>
    <code><? highlight_file("blah.php"); ?></code>
    Oh, steve - I don't think you need to replace the PHP tags if you use file_get_contents - It's stored in a string variable.
    good point, arkinstall.

    I tried. if not replace then show nothing even though the html stream has the php code. i don't know why. maybe my web server is not set well.

    and the function highlight_file() is pretty cool, i'll throw my code away. thanks arkinstall.
    * @location Vancouver, BC, Canada
    * @name Steve
    * @job PHP/MySQL, Drupal, WordPress Developer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •