簡體   English   中英

在Wordwrap中詢問php的合理性

[英]Ask justify in php with wordwrap

我使用自動換行功能php,但我想逐行進行辯解..這是我的簡單代碼:

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

您可以使用CSS將其存檔。 如果您可以使用CSS,請嘗試以下代碼。 希望這會幫助你。

CSS

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

PHP代碼

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM