【发布时间】:2023-03-28 03:18:02
【问题描述】:
我正在尝试修复冗长字符串的对齐问题,这是我的代码
<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 nl2br($lengthyString); ?>z<br>
</p>
</body>
</html>
但我错过了$lengthyString中的间距( )调整。我想显示长度字符串的新行应该与一个空格一致。然后我尝试了wordwrap()
<?php echo wordwrap($lengthyString,25," <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
【问题讨论】:
-
解释“它不起作用”...您是在浏览器中查看源代码还是仅查看渲染?如果我理解
wordwrap更有意义。nl2br没有,因为我在该字符串中没有看到“新行”。 -
我错过了下一行的间距,每一行开始都应该是统一的,这就是我正在尝试的事情
-
没有换行符可以转换成
-
你的输出是什么,你真正想要的输出是什么。对第 1 行、第 2 行等使用 list 和 aling
-
完全摆脱
&nbsp;s,使用CSS进行格式化。