March 1st, 2013, 09:24 AM
Ah, ok. Maybe I haven't gotten in the habit of such, because when I have variables within a line, I do something similar to:
Is that ok? Or is one way prefered over the other? And I do apologize again, newbie1234. for stepping in like this. :-/
$var = "Good afternoon, " . $name . " and welcome to our site!";
March 1st, 2013, 10:00 AM
That's the general solution. Inserting variables directly into strings is limited to special cases which don't require escaping or allow you to escape the whole string at once.
Originally Posted by Triple_Nothing
March 1st, 2013, 10:50 AM
Either way is fine, yes. If your variables require escaping, you can do it before the fact and use string interpolation, or do it inline using your method.
It's actually faster to echo a series of strings and variables using COMMAS, rather than concatenation:
Note that I changed your double-quotes to single (very slightly faster) and your periods to commas (very slightly faster).
echo 'Good afternoon, ', $name, ' and welcome to our site!';
Edit: When I said echo, I mean it. Echo is the only place this syntax works. /EDIT
Don't worry about stepping on newbie's toes, her homework was due yesterday, so if she still doesn't have it done she's going to have to deal with her professor, not us.
Last edited by ManiacDan; March 1st, 2013 at 11:00 AM.
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question
or you're a Help Vampire.
Trying to argue intelligently? Please read this.