You are currently viewing PHP Echo Space Between Variables | Multiple spaces
  • Post category:PHP

PHP Echo Space Between Variables | Multiple spaces

PHP echo space between variables

In this article, we will see PHP echo space between variables and multiple white spaces.

Multiple White Space

If there is more than one white space in a string; then the browser collapses all those white spaces into a single white space. Hence to add more than one white space in between words or characters we can use an HTML entity  

  •   – indicates nonbreakable whitespace, which adds a single space.

we can use   any number of times to add more white spaces.

Example

<?php
echo "Hello &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;World!";
?>

/*Output:
Hello     World!
*/
    1. In the above code, we printed “hello world”. I want to add five spaces between the variable.
    2. If you write the code below to insert five spaces:
      <?php echo "Hello     World!"; ?>

You will get only one space output like this:

Output: Hello World!
  1. So, we use the “&nbsp” statement to add multiple white space in PHP.

Leave a Reply