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 336819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:16:41+00:00 2026-05-12T10:16:41+00:00

In C you can continue a string literal in the next line escaping the

  • 0

In C you can continue a string literal in the next line escaping the newline character:

char* p = "hello \
new line.";


( My C is a bit rusty and this could be non 100% accurate )

But in php, the backslash is taking literally:

$p = "hello \
new line.";

I.E. the backslash character forms part of the string.
Is there a way to get the C behavior in PHP in this case?

  • 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-05-12T10:16:41+00:00Added an answer on May 12, 2026 at 10:16 am

    There’s a few ways to do this in PHP that are similar, but no way to do it with a continuation terminator.

    For starters, you can continue your string on the next line without using any particular character. The following is valid and legal in PHP.

    $foo = 'hello there two line 
    string';
    
    $foo = 'hello there two line 
        string';    
    

    The second example should one of the drawbacks of this approach. Unless you left jusity the remaining lines, you’re adding additional whitespace to your string.

    The second approach is to use string concatenation

    $foo = 'hell there two line'.
    'string';
    
    $foo = 'hell there two line'.
        'string';   
    

    Both example above will result in the string being created the same, in other words there’s no additional whitespace. The trade-off here is you need to perform a string concatenation, which isn’t free (although with PHP’s mutable strings and modern hardware, you can get away with a lot of concatenation before you start noticing performance hits)

    Finally there’s the HEREDOC format. Similar to the first option, HEREDOC will allow you to break your strings over multiple lines as well.

    $foo = <<<TEST
    I can go to town between the the start and end TEST modifiers.  
    
        Wooooo Hoooo.  You can also drop $php_vars anywhere you'd like.
    
    Oh yeah!
    TEST;
    

    You get the same problems of leading whitespace as you would with the first example, but some people find HEREDOC more readable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to thread this below function so that the background form can continue
Help, I'm deperate..i can't continue my app because of this: I have setup one
I recently switched to MongoDB and I am wondering if I can continue using
Sometimes a labeled break or continue can make code a lot more readable. OUTERLOOP:
Can anyone tell me the difference between break and continue statements?
How can you do a Press Enter to Continue in C?
can any one tell me how can change this java code into objective c.is
Can the Application Name passed to SQL Server (via the ADO Connection string) be
This is probably an easy question but I can't find the answer... I have
I like to write code using the ternary ?: operator like this: std::string result

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.