How to add extra whitespace in PHP?

后端 未结 14 1904
生来不讨喜
生来不讨喜 2020-12-02 22:44

I was wondering how can I add extra whitespace in php is it something like \\s please help thanks.

Is there a tutorial that list these kind of things th

相关标签:
14条回答
  • 2020-12-02 23:18

    You can also use this

    str_repeat("\x20", $numberOfRepeats);
    
    0 讨论(0)
  • 2020-12-02 23:19

    use this one. it will provide 60 spaces. that is your second parameter.

     echo str_repeat(" ", 60); 
    0 讨论(0)
  • 2020-12-02 23:22

    source

    <?php
    echo "<p>hello\n";
    echo "world</p>";
    
    echo "\n\n";
    
    echo "<p>\n\tindented\n</p>\n";
    
    echo "
    <div>
      easy formatting<br />
      across multiple lines!
    </div>
    ";
    ?>
    

    output

    <p>hello
    world</p> 
    
    <p> 
        indented
    </p>
    
    <div> 
      easy formatting<br /> 
      across multiple lines!
    </div>
    
    0 讨论(0)
  • 2020-12-02 23:26

    Like this:

     str_repeat('&nbsp;', 5); // adds 5 spaces
    
    0 讨论(0)
  • 2020-12-02 23:27

    To render more than one whitespace on most web browsers use &nbsp; instead of normal white spaces.

    echo "<p>Hello &nbsp;&nbsp;&nbsp; punt"; // This will render as Hello   Punt (with 4 white spaces)
    echo "<p> Hello       punt"; // This will render as Hello punt (with one space)
    

    For showing data in raw format (with exact number of spaces and "enters") use HTML <pre> tag.

    echo "<pre>Hello        punt</pre>"; //Will render exactly as written here (8 white spaces)
    

    Or you can use some CSS to style current block, not to break text or strip spaces (dunno bout this one)

    Any way you do the output will be the same but the browser itself strips double white spaces and renders as one.

    0 讨论(0)
  • 2020-12-02 23:31

    PHP is an easy language with multiple solutions. A Quick Solution would be using Double Quotes " ". Example Below.

    $var1 = "Hello";
    $var2 = "World";
    $var3 = "How";
    $var4 = "are";
    $var5 = "you";
    $var6 = "?";
    $var7 = ",";
    
    echo "$var1 $var2$var7 $var3 $var4 $var5$var6";
    
    //Output: Hello World, How are you?
    
    0 讨论(0)
提交回复
热议问题