Page 1 of 1

PHP Line Continuation Character?

Posted: Thu Jul 20, 2006 6:14 pm
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]

Posted: Thu Jul 20, 2006 6:15 pm
by daedalus__
$str = "i like milk
and cookies";

Posted: Thu Jul 20, 2006 6:17 pm
by sabastious
Thanks!

Posted: Thu Jul 20, 2006 6:25 pm
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";

Posted: Thu Jul 20, 2006 7:45 pm
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]

Posted: Thu Jul 20, 2006 8:04 pm
by Benjamin
I can't mark this thread as read :?

Posted: Thu Jul 20, 2006 8:26 pm
by MrPotatoes
i'd concat anyways just cuz. only because i'm used to it in C

Posted: Thu Jul 20, 2006 10:25 pm
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.

Posted: Fri Jul 21, 2006 5:50 am
by AngryPanda
Why not necessarily ... ?

Posted: Fri Jul 21, 2006 11:10 am
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;