Jump to content

php and plus sign spacing


hisoka

Recommended Posts

Plus sign is used in php for making white space. So

 

How to make php echo white space between two strings using plus sign . For example :

 

<?php

 

$string = "hello";

$string1= "world";

echo $string+$string1;

?>

 

I need a result as this

 

hello world

 

But how ?

Link to comment
Share on other sites

The plus sign is to operate with numbers. If you want to join the strings together, use the concatenation operator, which is a dot.

 

You can concatenate a literal string with a space in it to add a space between the other strings.

echo $string1 . ' ' . $string2;

An alternative way is to use double-quoted strings:

echo "$string1 $string2";
  • Like 1
Link to comment
Share on other sites

Another way:-

 

echo $string1 , ' ' . $string2;

 

or

 

echo $string1 , ' ' . $string2; // put in one space

 

using this method you can make it as many spaces as you want eg

 

echo $string1 , '   ' . $string2; //this will put in 3 spaces

 

and

 

echo $string1 , '     ' . $string2; //will put in 5

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...