Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9281369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:06:10+00:00 2026-06-18T18:06:10+00:00

I often have to assign large strings to variables. In the source code I

  • 0

I often have to assign large strings to variables. In the source code I preferably want to keep my lines within 80 characters.

Ideally I want to be able to lay these literal strings out on multiple lines.

What I want to avoid is using concatenation, or function calls (e.g. preg_replace()), to join multiple strings together in one. I don’t like the idea that I have to invoke language features in order to improve the style of my code.

Example of something I would like:

    $text = <<<TEXT
Line 1
Line 2
Line 3
TEXT;
    echo($text);

This should output:

Line1Line2Line3

Is this possible?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:06:12+00:00Added an answer on June 18, 2026 at 6:06 pm

    There are a few options:

    1. Just concatenate (preferred)

    2. Use array constructs

    3. Use sprintf()

    Just concatenate:

    echo 'long long line1'
        . 'another long line 2'
        . 'the last very long line 3';
    

    What about efficiency?

    The above code compiles into the following opcodes (which is what’s run):

    5    0  >   CONCAT      ~0      'long+long+line1', 'another+long+line+2'
         1      CONCAT      ~1  ~0, 'the+last+very+long+line+3'
         2      ECHO        ~1
    

    As you can see, it builds the string by concatenating the first two lines, followed by the last line; in the end ~0 is discarded. In terms of memory, the difference is negligible.

    This is what a single echo statement would look like:

    3    0  >   ECHO                'long+long+line1another+long+line+2the+last+very+long+line+3'
    

    Technically it’s faster because there are no intermediate steps, but in reality you won’t feel that difference at all.

    Using array:

    echo join('', array(
        'line 1',
        'line 2',
        'line 3',
    ));
    

    Using sprintf():

    echo sprintf('%s%s%s',
        'line 1',
        'line 2',
        'line 3'
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often have a situation in my Java code when I need to set
I quite often have rows of code like the following: UPDATE my_table SET name
I often need to assign a variable, if the source value is set. So
I have two pieces of code I use often in which I use the
Somewhat often I have to build tables and assign to the table headers names
Before using the Task Parallel Library, I have often used CorrelationManager.ActivityId to keep track
Possible Duplicate: Assign function arguments to `self` Often I have constructors that look like
I often have some piece of code that repeats. Usually, I put them in
I often have to transfer large files >50GBs sometimes >100GBs between drives both internal
I often want to find uncommented print statements in my (Python) file. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.