Announcement

Collapse
No announcement yet.

Ignore PHP When Needed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ignore PHP When Needed

    Hello Everybody.

    I have a file, bla.php, which contains both HTML and PHP code which I use to create my pages.

    I use 'fopen' and 'fread' to open and read the file, then I print it on the screen and both HTML and PHP are working perfectly.

    Now to my problem. I want to load the contents of the same page, HTML and PHP into a textbox, so I can edit them online. Problem is, when I load them, the PHP parts are being executed automatically in the textbox. That's not what I want, as I can't edit any part of the PHP code that why.

    My question is, how can I make it ignore the PHP code when I echo it.
    I thought about 'strip_tags', and tried some more functions, but couldn't get it to work.

    I will appreciate any kind of help and ideas.

    Thank you all.

  • #2
    I use 'fopen' and 'fread' to open and read the file, then I print it on the screen and both HTML and PHP are working perfectly.
    How are you doing that? To make the PHP execute don't you have to eval it or something? freading it into a variable won't execute the code, at least I didn't think so...

    Comment


    • #3
      If you read it from a .PHP file it executes just fine.
      I thought i'll have a problem with that too, but it's just working smoothly

      Any ideas how to solve my problem?

      Comment


      • #4
        if your opening an HTML file and want to place it into any input you'll need to run it though
        htmlspecialchars prior to putting it in the input tag
        Scott MacVicar

        My Blog | Twitter

        Comment


        • #5
          Yes, I know, I already did that, let me explain further.

          I have a file:

          Code:
          <html> 
          bla bla...
          <?php echo ""; ?>
          bla...
          </html>
          When I read it, it's just being written, and automatically executed.
          Which means, i'll get all the HTML tags written fine, and when a PHP part comes up, I won't get <?php.. etc, but the result, what the echo prints.

          Now, I want to put that into a textbox, but I want to avoid the PHP from running, I want to see those tags.

          Understand?

          Comment


          • #6
            would be easier if we had all the code.

            it definately shouldn't be echo'd just reading it.
            Scott MacVicar

            My Blog | Twitter

            Comment


            • #7
              Okay here we go:

              PHP Code:
              <?php 
              $file
              =fopen('bla_data.php''r');
              $get_filed=fread($file10240);
              $var=htmlspecialchars($get_filed);
               
              echo 
              $var
              fclose($file);
              ?>
              that executes the php in the file, I think that's because of the .PHP extension it has.

              Comment


              • #8
                The one thing you could do is have it copy the file to a non .php file temporarily, read the file, then delete it.

                Comment


                • #9
                  ah ok try putting in

                  ./blah_data.php and see if that makes a difference. You should always use ./ as this saves on extra stats to the folder since if you dont add it, then PHP checks your include directories before checking the directory the script is in.
                  Scott MacVicar

                  My Blog | Twitter

                  Comment


                  • #10
                    Never mind guys I solved it myself

                    Thanks anyway.

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X