首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中用wordwrap询问justify

在php中用wordwrap询问justify
EN

Stack Overflow用户
提问于 2015-03-27 11:21:35
回答 1查看 1.1K关注 0票数 1

我使用的是文字包装函数php,但我希望逐行对齐。这是我的简单代码:

代码语言:javascript
复制
<?php
$text = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software.';

$pish = wordwrap($text, 60, '|', 1);
$psh =explode('|',$pish);

echo $psh[0]."<br>";
echo $psh[1]."<br>";
for($i=2;$i<10;++$i){
    echo $psh[$i]."<br>";
}

?>

结果kode:

代码语言:javascript
复制
Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industrys
standard dummy text ever since the 1500s, when an unknown
printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries,
but also the leap into electronic typesetting, remaining
essentially unchanged. It was popularised in the 1960s with
the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing
software.

如何证明这一点是合理的?

我想要结果:

代码语言:javascript
复制
Lorem  Ipsum  is  simply  dummy  text  of  the  printing and
typesetting  industry.  Lorem  Ipsum  has been the industrys
standard  dummy  text  ever since the 1500s, when an unknown
printer  took a galley  of  type  and scrambled it to make a
type specimen book. It has survived not only five centuries,
but  also  the  leap  into electronic typesetting, remaining
essentially  unchanged. It was popularised in the 1960s with
the  release  of  Letraset  sheets  containing  Lorem  Ipsum
passages,   and   more   recently  with  desktop  publishing
software.
EN

回答 1

Stack Overflow用户

发布于 2015-03-27 11:56:17

您可以使用css对其进行归档。如果使用css对你来说没问题,那就试试下面的代码。希望这能对你有所帮助。

CSS

代码语言:javascript
复制
<style>
.fulljustify {
   text-align: justify;
   width:408px;
}
.fulljustify:after {
   content: "";
   display: inline-block;
   width: 100%;
}
</style>

php代码

代码语言:javascript
复制
<?php
 $text = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software.';
 $pish = wordwrap($text, 60, '|', 1);
 $psh =explode('|',$pish);
 echo "<div class='fulljustify'>";
 echo $psh[0]."</div>";
 echo "<div class='fulljustify'>".$psh[1]."</div>";
 for($i=2;$i<10;++$i){
  echo "<div class='fulljustify'>".$psh[$i]."</div>";
 }
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29292756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档