tags:

views:

92

answers:

5

I was wondering how can I print out whitespace in the following code below.

<?php echo "$first_name", "$last_name" ; ?>
A: 
<?php 
echo "$first_name $last_name"; 
?>
Just Jules
+2  A: 

Just, well, add whitespace to your output?

<?php echo "$first_name $last_name with     some    whitespace" ; ?>

Sometimes, it the obvious answer is right - even in PHP!

Adam Wright
I was thinking that, but I was wondering if there was a better way. thanks.
sq
Except for the fact that most browsers will treat multiple spaces as a single space. If I really need to display multiple spaces, I normally use an " " or enclose the output in <pre></pre> tags
Tom
A: 

Notice that when you use ' any var aren't display, with " does.
So, good is:
<?php echo "$first_name $last_name" ; ?>
bad
<?php echo '$first_name $last_name' ; ?>

Rin
+2  A: 

If you want to concatenate several strings without the double quotes (e.g. when using single quotes):

$string = $first_name . ' ' . $last_name; // The dot is a concatenation operator
Henrik Paul
A: 

If you want to keep using commas:

<?php echo  $first_name, ' ', $last_name; ?>
rojoca