用wordwrap在php中提出问题

时间:2015-03-27 03:21:35

标签: php html justify

我使用wordwrap函数php但我想逐行make是合理的.. 这是我的简单代码:

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

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.

如何证明这一点?

我想要结果:

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.

1 个答案:

答案 0 :(得分:0)

您可以使用css对此进行归档。如果css using对你没问题,请尝试以下代码。希望这会对你有所帮助。

CSS

<style>
.fulljustify {
   text-align: justify;
   width:408px;
}
.fulljustify:after {
   content: "";
   display: inline-block;
   width: 100%;
}
</style>

php code

<?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>";
 }
?>