在Codeigniter中将输出限制为仅3行

时间:2015-12-05 06:59:20

标签: javascript php css codeigniter

如何将内容限制为仅限一定数量的字符。我想将行数限制为3行,每行6个单词,并使用中断来显示下一行中的后6个单词。 $ row-> openletter为我提供了超过1000个单词的完整结果。我已经在控制器中加载了文本助手。请找到我想要实现的附图。如何限制$ row-> openletter以在每行中仅显示6个单词并将行数限制为3?

<?php 	   
			echo "</li>";
		echo "</ul>"; 
	echo "</div>";
echo "</div>";
	echo "<div class='news-v2-desc'>";
		echo "<h3>";
		<a href="<?php $this->load->helper('url'); echo base_url();?>index.php/Welcome/indexes?id=<?php $data=$row->open_id; echo $data; ?>">
			<?php $ima=$row->title; echo $ima; ?>
		</a>
		<?php echo "</h3>";
		echo "<small>By Admin | California, US | In <a href='#'>Art</a></small>";
		echo "<p>";
			$string = word_limiter($row->openletter, 4);
			echo  $string;
		echo "</p>";   
	echo "</div>";
echo "</div>";
}
?> 

enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个

$para = '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.';

$pos = strpos($para, ' ', 200);
echo substr($para,0,$pos )

Phpfiddle Preview

答案 1 :(得分:1)

根据您的问题$ string = $ row-&gt; openletter;应分为3行和每行6个字。我认为这段代码将满足您的问题。让我知道结果

<?php
$string = "Here is a nice text string consisting of eleven words.Here is a nice text string consisting of eleven words";
$str=explode(' ',$string );//stores each word as a array 
$a=0;
for($i=0;$i<3;$i++){
$a=$a+$i;
$b=$a+1;
$c=$b+1;
$d=$c+1;
$e=$d+1;
$f=$e+1;
$a=$f;
echo $str[$a]." ".$str[$b]." ".$str[$c]." ".$str[$d]." ".$str[$e]." ".$str[$f];
echo"<br>";
}
?>