我正在尝试修复冗长的字符串对齐问题,这是我的代码
<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
中的间距(&amp; nbsp)调整。我想要显示长度字符串的新行应该是一个空格意图的统一。然后我尝试wordwrap()
<?php echo wordwrap($lengthyString,25," <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
答案 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。
 
也是一个角色,所以你只是在前面放一个额外的角色。
<强>更新强>
<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%;">
Line1<br>
Line2<br>
<?php echo $lengthyString; ?><br>
</p>
</body>
</html>