PHP Question
#1

Would this work?

$msg = "Hello .'$username'. you are cool.";

or is it:

$msg = "Hello '.$username.' you are cool.";

Thank you in advance.

fixed 4 pot. mwah xoxoxo
Reply
#2

You dont need apostrophe's for that, the last time I checked, just $username should work. but what do I know, not a PHP user.
Reply
#3

Quote:
Originally Posted by Riddy
Посмотреть сообщение
You dont need apostrophe's for that, the last time I checked, just $username should work.
I'm sure you needed one of those as it shows it's a variable needed to print the variable string.
Reply
#4

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
I'm sure you needed one of those as it shows it's a variable needed to print the variable string.
You might aswell try both if you think its those.
Reply
#5

I don't understand why you don't just try them and find out for yourself.
Reply
#6

Neither should work. You need to be consistent with your use of the punctuation, you can't use " and then use ', you use both.

This isn't common sense, no?
Reply
#7

If you use double quotes then you can insert variables into your string like this:
PHP код:
"Hello $username!" 
If you use single quotes you can do it like this:
PHP код:
'Hello' $username '!' 
And if you do this, it will insert $username literally.
PHP код:
'Hello $username!' 
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
If you use double quotes then you can insert variables into your string like this:
PHP код:
"Hello $username!" 
If you use single quotes you can do it like this:
PHP код:
'Hello' $username '!' 
And if you do this, it will insert $username literally.
PHP код:
'Hello $username!' 
Thanks for taking time to explain.
Reply
#9

PHP код:
"Hello " $username "!"
This is also valid.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)