我怎樣才能獲取變量的前幾個單詞,例如$ data。我試圖創建一篇文章預覽部分,該變量是一篇文章。我試圖僅顯示它的預覽。抓取變量的部分以在HTML內回聲
<?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>
任何幫助是極大的讚賞。
SQL:'SELECT作者,數據,踵,SUBSTRING(數據,0,100)...' PHP:http://php.net/手動/ EN /函數的n.substr.php – Ejaz 2013-04-10 21:58:16