php - &nbsp 在 worwrap 中不工作

标签 php html css 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 中的间距( )调整。我想显示 lenghty 字符串的新行应该与一个空格一致。然后我尝试了 wordwrap()

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

但这是行不通的,有什么解决方案可以在 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

最佳答案

根据上面的评论:

<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>

关于php - &nbsp 在 worwrap 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50726429/

相关文章:

jquery - 溢出时防止父容器滚动 :scroll container has reached its limits

javascript - Hello bar 应用程序使我的导航移动崩溃。

php - 通过php读取文件

php - 逻辑运算符 AND 与 php 正则表达式

php - 多次查询: Multi Variables or One Query

javascript - 获取错误 IE 中网页访问被拒绝

HTML 和高度 : how do I make a widget as high as _all_ of its descendants?

php - 在 Wordpress 中编辑现有的 WooCommerce 元框

jquery - 如何消除标题和导航栏之间的差距?

jquery - 如果 html、正文溢出-x : hidden,则 ScrollTop 动画不起作用