IWETHEY v. 0.3.0 | TODO
1,095 registered users | 1 active user | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New I thought the period was used to...
Oh, and while I can't remember the exact syntactic difference, I know I prefer a period instead of a comma in

echo 'The time is now ',$time;



I thought the period was used to append information to something in the previous line of a script?

For example:


echo 'Hello';
echo .' World';


Gave you "Hello World" -- both appearing on one line.
"We are all born originals -- why is it so many of us die copies?"
- Edward Young
New Err, not really
I thought the period was used to append information to something in the previous line of a script?

For example:


echo 'Hello';
echo .' World';


Gave you "Hello World" -- both appearing on one line.

If you run that it will print 'Hello World' on one line, but it has nothing to do with the period. PHP don't automatically include any line breaks, so everything goes on one line unless you include some yourself. This can be confusing, because if the output is HTML, it will often be rendered on multiple lines even if the output is on one.

Doing
echo 'This is one <br /> line of output';
will produce one line of output but render as two lines of HTML. But doing
echo "This is one line /n";
echo "and this is another one";
will output two lines and render as one in HTML.

The period is string concatenation in PHP. $name = 'Jay' . ' ' . 'Mehaffey' sets $name to 'Jay Mehaffey'.

The echo command takes any number of values, seperated by commas, and outputs them.

Thus echo 'The time is now ',$time; and echo 'The time is now' . $time are actually doing two subtly different things. The first outputs 'The time is now' and then outputs $time right after it. The second puts 'The time is now' and $time together into one string and then outputs that.

Jay
     Learning PHP Part Deux: When to use (') and when to use (") - (cwbrenn) - (12)
         Keeping in mind that I don't know PHP at all... - (Yendor)
         Double quotes force evaluation of the contents - (drewk) - (2)
             I thought the period was used to... - (cwbrenn) - (1)
                 Err, not really - (JayMehaffey)
         Well they are never required - (JayMehaffey)
         On quoting array keys - (drewk) - (5)
             I have to say... - (cwbrenn) - (4)
                 It looks better in vim - (drewk) - (3)
                     Kate or Quanta... - (cwbrenn) - (2)
                         I can't write code without syntax highlighting - (drewk) - (1)
                             both Kate and Quanta have syntax highlighting -NT - (cwbrenn)
         Sometimes it matters, sometimes it doesn't. - (static)

Make your blood boil?
42 ms