PHP Line Continuation Character?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

PHP Line Continuation Character?

Post by sabastious »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm an ASP Programmer making the switch to PHP. In ASP/VBScript when you want to goto the next line in the middle of a code you use whats called a Line Continuation Character.

Example:
[syntax="asp"]
myString = "Hello my name is alex I am a super cool dude that likes cheese" & _
"I also like milk" & _
"I also like the number 8"
See the underscore, it allows me to continue the code on the next line without generating an error.

Is there a PHP equivelent?


Weirdan | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

$str = "i like milk
and cookies";
sabastious
Forum Newbie
Posts: 8
Joined: Thu Jul 20, 2006 6:09 pm

Post by sabastious »

Thanks!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

PHP doesn't require it, but you can also concatenate strings in similar fashion...

Code: Select all

$myString = "Hello my name is alex I am a super cool dude that likes cheese" .
"I also like milk" .
"I also like the number 8";
AngryPanda
Forum Newbie
Posts: 16
Joined: Wed Jul 19, 2006 12:18 am

Post by AngryPanda »

Keep in mind those examples aren't the same, though...

[edit]

Just to elaborate, the milk and cookies example will have newlines in the string, the concatenated example will not.

[/edit]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I can't mark this thread as read :?
User avatar
MrPotatoes
Forum Regular
Posts: 617
Joined: Wed May 24, 2006 6:42 am

Post by MrPotatoes »

i'd concat anyways just cuz. only because i'm used to it in C
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

AngryPanda wrote:Keep in mind those examples aren't the same, though...

[edit]

Just to elaborate, the milk and cookies example will have newlines in the string, the concatenated example will not.

[/edit]
Not neccasarily.
AngryPanda
Forum Newbie
Posts: 16
Joined: Wed Jul 19, 2006 12:18 am

Post by AngryPanda »

Why not necessarily ... ?
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

You can also do heredoc syntax. I use it sometimes for large blocks of HTML, since you don't have to escape double or single quotes. Some editors (like Crimson) will choke on it, and mistake it for lines of code.

Code: Select all

$myVar = <<<EOT
The string starts here
This is a new line
Another new line
No Escaping "double quotes"
or 'single quotes'
EOT;
Post Reply