How can I read a php file into a string using php?

后端 未结 2 1580
隐瞒了意图╮
隐瞒了意图╮ 2021-01-29 10:06

Lets say I want to use a php script to read the current page\'s code into a string how would I do that without executing the php contents of the page?

For example using<

相关标签:
2条回答
  • 2021-01-29 10:51

    file_get_contents() will only execute that file and give you the output as the content if you refer to it as a URL. If you just give a filename, it will attempt to read it from (in your case) the current directory.

    0 讨论(0)
  • 2021-01-29 11:05

    Actually there is one way to execute PHP file and get the content into a variable.

    You can use the ob_start() and ob_get_clean() functions.

    ob_start();
    include "teste.php";
    $String = ob_get_clean();
    
    0 讨论(0)
提交回复
热议问题