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

标签 javascript php css codeigniter

如何将内容限制为只有一定数量的字符。我想将行数限制为 3 行,每行 6 个单词,并在下一行中显示接下来的 6 个单词。 $row->openletter 给我超过 1000 个单词的完整结果。我已经在 Controller 中加载了文本助手。请找到我想要实现的附加图像。我如何限制 $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

最佳答案

试试这个

$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

关于javascript - 在 Codeigniter 中将输出限制为仅 3 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34102239/

相关文章:

php - 如何在 SQL 中从同一个表中的其他两个值创建一个值?

php - 使用 lsof 查找单个打开文件的最快方法是什么?

css - 内容属性文本颜色 - css

javascript - 有没有办法将 SVG 元素放在具有绝对位置的 HTML div 之上?

css - 如何在 Spring MVC 中禁用标准 css

javascript - 如果内容太长,使用 JS 更改/设置 div 高度

javascript - 调用 jquery .on(document.body) 而不是特定元素有缺点吗

javascript - jQuery:如何在出现滚动条时触发窗口调整大小事件

javascript - 将 SnapshotChanges 与 CombineLatest 结合使用

php - 在 PHP 中使用游标执行存储过程