Dzoki
Dzoki

Reputation: 739

Include text in file without <?php ?> tags [file_get_contents]

I have noobish question for you guys. I'm making my private sandboxie where you can test your code. So for now what I'm making is that you write the code, code is executed and you can see the result BUT i want the code you written in the textbox.

Now the problem is, I want that text from .php file to be shown without tags. I might be idiot but I just don't remember how to do it.

so actually code is like

            if($_GET['f']){
                echo file_get_contents("files/".$_GET['f'].".php");
            }else{
                echo "echo \"Hello world\";";
            }

if you don't understand what I want I can post more info etc but I think its obvious:)

Upvotes: 0

Views: 897

Answers (3)

Mob
Mob

Reputation: 11106

Use include(); and require(); would help you include the file. Use eval(); to execute the code.

To see the actual source of the file and strip the <?php ?> tags do this

   $file = file_get_contents('time.php');
    $ll = array('<?php','?>');

    echo str_replace($ll, "", $file);

Upvotes: 0

genesis
genesis

Reputation: 50982

Do you mean something like

<?php 
echo str_replace(array('<?php', '?>'), '', file_Get_contents('file.php'));

?

Upvotes: 2

Ry-
Ry-

Reputation: 225281

The include function :)

include("files/" . $_GET['f'] . ".php");

But! Never read a file directly from $_GET. Someone could put in ../../sensitiveinformation.txt or something.

Upvotes: 1

Related Questions