例如,我将如何获取变量的前几个单词,例如 $data。我正在尝试创建一个文章预览部分,该变量是一篇文章。我想当然只显示它的预览。
<?php
$sql = "SELECT author, data, postdate, Title, previewimg FROM articlepreview ORDER BY RAND() LIMIT 1";
$query = mysqli_query($db_conx,$sql);
$prev = "";
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$a = $row["author"];
$data = $row["data"];
$postdate = $row["postdate"];
$title = $row["Title"];
$previewimg = $row["previewimg"];
$prev .= '
<div class="wrapPreviewArticle">
<div style="headerPreview"><h4>'.$title.'</h4></div>
<div class="wrapPreviewRow">
<div style="imagePreview"><img src="'.$previewimg.'" height="20%" width="20%" alt="'.$title.'" /></div>
<div clas="wordPreview">'.$data.'</div>
</div>
</div>
';
}
?>
一旦我得到这个,我会吐出变量
<body>
<div><?php echo $prev; ?></div> <!--with only the desired portion.-->
</body>
任何帮助是极大的赞赏。