我正在尝试解决冗长字符串的对齐问题,这是我的代码
<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
中的间距( )调整。我想显示 lenghty 字符串的新行应该与一个空格一致。然后我尝试了 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
最佳答案
根据上面的评论:
<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>
关于php -   在 worwrap 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50726429/