2

I am a beginner PHP writer so please bear with me.

I have a simple situation that is sort of like this:

Line 1 $output .= 'ABC'

Line 2 $output .= 'DEFGHIJKLMN'

Line 3 echo $output;

Now, the code within my 'DEFGHIJKLMN' string has become super long. I am thinking about moving the content of 'DEFGHIJKLMN' to an external file for ease of editing, and somehow make the new file append to the end of $output.

So now I need to edit Line 2 to target the external file.

Please let me know how to do this, thank you.

2 Answers 2

3

Well, to append the contents of a file, use

$output .= file_get_contents("path_to_my_file.txt");

If you just want to break it across multiple source lines, do

$output .= "Long Line 123".
           "Continues here";
Sign up to request clarification or add additional context in comments.

Comments

0

You must have an $output variable in your code somewhere in a file you included. You can overwrite the variable like this:

$output = 'ABC';

instead of

$output .= 'ABC';

so your code could look like:

$output = 'ABC';
$output .= 'DEFGHIJKLMN';
echo $output;

or just change your variable name. That's what I would do. I also wouldn't see a need to concatenate this String.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.