开发者

file_get_contents() in php not working

I am using file_get_contents() in php that is not working when i am using like this. the file name is index.php

<?php
    $content = "开发者_JS百科hi";
    $content = file_get_contents('index.php');
    echo $content;
?>

I thought it prints hi more than one tym.. but it print that only one time.. why? tell me please...


I think what you're trying to do here, is first give a value to $content, and then add whatever is in index.php.

If that's the case, do this:

<?php
$content  = "hi";
$content .= file_get_contents('index.php');
echo $content;
?>

With = you redefine a variable, so it doesn't matter what it was before.
With .= you add something to a variable.


Step 1 : check path & access rights.

From your codes, your variable $content is overwritten by the result returned by file_get_contents() . Therefore, your echo is printing our the result returned by the function.

p.s. the function should work. Read the manual.


I think you’re trying to use recursion here. If you view source it probably says,

hi<?php
    $content = "hi";
    $content .= file_get_contents('index.php');
    echo $content;
?>

The reason it is only printing “hi” is because your browser doesn't recognize the <php tag as valid HTML so it ignores it.

If my assumption is correct, then my question is Why do you want to do this? What are you trying to accomplish?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜