开发者

include file content php

I want to include the content from a php file into开发者_运维知识库 another php file. (It's in a wordpress site)

Include or require won't work because it's just including the file, I need the content itself.

file_get_contents is also not working because it just displays my php code and does not execute it.

what function do I have to use?


I don't fully understand your question either, but I think this might work for you:

ob_start();
include('yourfile.php');
$contents = ob_get_clean();

$contents will now contain the 'contents' (the output) of your PHP script.


Include or require won't work because it's just including the file

Pause. What? Include includes the code in the file for you. I'm sure this is what you want. For instance, see the code below. test.php has vars.php included in it and its able to echo the variables from vars.php

//vars.php
----------
<?php

$color = 'green';
$fruit = 'apple';

?>
----------

//test.php
----------
<?php

echo "A $color $fruit"; // A

include 'vars.php';

echo "A $color $fruit"; // A green apple

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜