How to Add Extra Whitespace in PHP

How can I add space in PHP between two outputs

use the below code

<?php
echo 'Welcome '.$_GET['name'];
?>

  is the html entity code for creating an single space character.

You can also use the below code:

<?php
echo 'Welcome '.$_GET['name'];
?>

Will also work because one empty space is interpreted by the browsers directly.

How to add a space after every character in a string in php?

You can use implode you just need to use str_split first which converts the string to an array:

$password="1bsdf4";    
$formatted = implode(' ',str_split($password));

http://www.php.net/manual/en/function.str-split.php

Sorry didn't see your comment @MarkBaker if you want to convert you comment to an answer I can remove this.

how to add a whitespace in PHP in input box?

Change value="" to value="<?php echo $_SESSION['age']. " " ."year"; ?>"

you have not concatenated a space there. Please see . " " .

excess whitespace in php echo

Do you have a closing php tag at the end of m/includes/globals.php? Maybe there is some whitespace after the closing tag.

PHP adds extra whitespace on require

Problem solved! This took forever to figure out. The short answer is that my php files were UTF-8 encoded. Changing this in Notepad++ to ANSI fixed it.

I only found the real cause of the problem by doing a character-by-character comparison of the output HTML - one output from where 'require_once' was used and one where the code was manually pasted in place.

In a visual comparison of the output, both appeared identical - same length, no extra/different characters. But when pushed through preg_split('//', $string), and looped through character by character, 3 extra "invisible" characters were revealed at the start of each require_once insert point. I idenitified these as the ASCII characters ï, » and ¿ (a double-dotted i, a right chevron and an upside-down question mark).

Changed the encoding to ANSI (I discovered this as the cause when I recreated one of the scripts in Notepad word-for-word and it did not suffer the same issue), and the extra lines have gone.

Can't add more than one space in the string

You could use  

    <?php

$str1 = 'merry';
$str2 = 'christmas';
$concat = $str1.'      '.$str2;
echo $concat;
?>


Related Topics



Leave a reply



Submit