在worwrap不工作

时间:2018-06-06 17:39:02

标签: php html5 css3 php-7

我正在尝试修复冗长的字符串对齐问题,这是我的代码

  <html>
    <head></head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%">&nbsp;Line1<br>
    &nbsp;Line2<br>
    &nbsp;<?php echo nl2br($lengthyString); ?>z<br>
    </p>

    </body>
    </html>

但是我错过了$lengthyString中的间距(&amp; nbsp)调整。我想要显示长度字符串的新行应该是一个空格意图的统一。然后我尝试wordwrap()

<?php echo wordwrap($lengthyString,25,"&nbsp;<br>\n");?>

但这不起作用,是否有任何解决方案可以在&nbsp

中加入wordwrap

预期产出:

 Line1
 Line2
 This is the lengthy 
 string ,but i miss the 
 spacing after second 
 line. The length and 
 contents may vary

但我喜欢这个

 Line1
 Line2
  This is the lengthy 
string ,but i miss the 
spacing after second 
line. The length and 
contents may vary

1 个答案:

答案 0 :(得分:1)

基于上述评论:

<html>
    <head></head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%;">
        Line1<br>
        Line2<br>
        <?php echo $lengthyString; ?><br>
    </p>

    </body>
    </html>

对于<p></p>标记内的空格,请使用css。 &nbsp也是一个角色,所以你只是在前面放一个额外的角色。

<强>更新

<html>
    <head>
    <style>
    p{
        white-space: nowrap;
    }
    </style>
    </head>
    <body>
    <?php $lengthyString = "This is the lengthy string ,but i miss the spacing after second line. The length and contents may vary"; ?>
    <p style="width:25%;">
        &nbsp;Line1<br>
        &nbsp;Line2<br>
        &nbsp;<?php echo $lengthyString; ?><br>
    </p>

    </body>
    </html>