我想将读取的文件输出存储在变量中

时间:2018-06-27 16:50:47

标签: php file fileoutputstream

在PHP中,我希望每个字符串都由“ fgets()”函数在单独的变量中读取。 下面是我的代码

$handle = @fopen("txtfile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}

此代码的输出是:

I am Demo

我希望此输出为:

$word1 = I
$word2 = am
$word3 = Demo

1 个答案:

答案 0 :(得分:0)

{
  AWS::ElasticBeanstalk::ConfigurationTemplate
    {
      "Type" : "AWS::ElasticBeanstalk::ConfigurationTemplate",
      "Properties" : {  
        "ApplicationName" : String,
        "Description" : String,
        "EnvironmentId" : String,
        "OptionSettings" : [ ConfigurationOptionSetting, ... ],
        "PlatformArn" : String,
        "SolutionStackName" : String,
        "SourceConfiguration" : SourceConfiguration
      } 
    }
}

现在您将每个单词保存在不同的变量中