【问题标题】:Restrict output to only 3 lines in Codeigniter在 Codeigniter 中将输出限制为仅 3 行
【发布时间】:2016-03-10 04:57:07
【问题描述】:

如何将内容限制为仅一定数量的字符。我想将行数限制为 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>";
}
?> 

【问题讨论】:

  • 您需要如图所示的输出。我是对的吗?
  • 你需要6个字3行对
  • @你如何接受阿卜杜拉的回答。他做了替代功能。它不会满足你的问题。你要求每行 6 个字,这两个 3 行。它将如何工作?

标签: javascript php css codeigniter


【解决方案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

【讨论】:

    【解决方案2】:

    根据您的问题 $string = $row->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>";
    }
    ?>  
    

    【讨论】:

    • @shank 但是你已经接受了另一个答案问题解决了吗?
    • @shank 尝试更新的答案。让我知道输出是什么
    猜你喜欢
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 2013-08-21
    相关资源
    最近更新 更多