PHP Concatenate file output to string

Bryan Zwicker

I am rewriting a piece of a program to change it from using "echos" throughout the script to create a large output variable using Heredocs instead, which outputs at the end of the file.

A piece of the script includes another PHP file that directly outputs HTML and has php logic within the HTML it outputs. This file is used by other pieces of the overall program that are not yet being rewritten (due to time constraints).

Is it possible to append the output of another file to an $output variable? I've tried doing this, but it it doesn't work for string appending:

$output .= include 'foo.php';

$output .= file_get_contents('foo.php');

The file_get_contents wrote all the PHP logic directly in HTML, as I suspected it would and the straight 'include' echo'd the HTML as I also expected.

Is there a method to get the output buffer of the file and append to a string?

EDIT: Nevermind the question, I completely forgot about OB_Buffering. Added an answer with my solution, no need to answer this one

Bryan Zwicker

I feel stupid. I found the answer 5 minutes after posting, I completely forgot about ob_buffering:

ob_start();
include('./foo.php');
$output .= ob_get_contents();
ob_end_clean();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Concatenate output of file dialog in 1 string

From Dev

Concatenate a string with the output of a php function as a parameter of anouther function

From Dev

PHP read php file output and use it as a string

From Dev

PHP read php file output and use it as a string

From Dev

Explode concatenate string from text file with new line, PHP

From Dev

Explode concatenate string from text file with new line, PHP

From Dev

How to concatenate string in php?

From Dev

Concatenate string and number in batch file

From Dev

How to concatenate string in php with conditions?

From Dev

Is it safe to concatenate `null` with a string in PHP?

From Dev

How to concatenate string continuously in php?

From Dev

Concatenate HTML string and variable in PHP

From Dev

Concatenate specific lines and output the results in a new file

From Dev

PHP: How to generate indexed name with string in file output?

From Dev

Include a php file, but return output as a string instead of printing

From Dev

Python, concatenate each line of a file with one string

From Dev

How to concatenate a string from an included file in bash

From Dev

String Output in a data file

From Dev

PHP using array(?) to concatenate argument string?

From Dev

String Concatenate and Hashing Difference between Ruby and PHP

From Dev

How can I concatenate a string with variables in PHP?

From Dev

How to concatenate and string and escapte characters in php

From Dev

PHP - Formatting string output

From Dev

PHP - Formatting string output

From Dev

Store PHP Output To File?

From Dev

Store PHP Output To File?

From Dev

Is there a way for concatenate two strings and then process the result inside the Output tags not as a string?

From Dev

Need to concatenate a string to each line of ls command output in unix

From Dev

output value of array to string in file

Related Related

  1. 1

    Concatenate output of file dialog in 1 string

  2. 2

    Concatenate a string with the output of a php function as a parameter of anouther function

  3. 3

    PHP read php file output and use it as a string

  4. 4

    PHP read php file output and use it as a string

  5. 5

    Explode concatenate string from text file with new line, PHP

  6. 6

    Explode concatenate string from text file with new line, PHP

  7. 7

    How to concatenate string in php?

  8. 8

    Concatenate string and number in batch file

  9. 9

    How to concatenate string in php with conditions?

  10. 10

    Is it safe to concatenate `null` with a string in PHP?

  11. 11

    How to concatenate string continuously in php?

  12. 12

    Concatenate HTML string and variable in PHP

  13. 13

    Concatenate specific lines and output the results in a new file

  14. 14

    PHP: How to generate indexed name with string in file output?

  15. 15

    Include a php file, but return output as a string instead of printing

  16. 16

    Python, concatenate each line of a file with one string

  17. 17

    How to concatenate a string from an included file in bash

  18. 18

    String Output in a data file

  19. 19

    PHP using array(?) to concatenate argument string?

  20. 20

    String Concatenate and Hashing Difference between Ruby and PHP

  21. 21

    How can I concatenate a string with variables in PHP?

  22. 22

    How to concatenate and string and escapte characters in php

  23. 23

    PHP - Formatting string output

  24. 24

    PHP - Formatting string output

  25. 25

    Store PHP Output To File?

  26. 26

    Store PHP Output To File?

  27. 27

    Is there a way for concatenate two strings and then process the result inside the Output tags not as a string?

  28. 28

    Need to concatenate a string to each line of ls command output in unix

  29. 29

    output value of array to string in file

HotTag

Archive