Php 仅显示内容中的20个字符?显示段落?
我有另外一个问题需要帮助。我只想显示“内容”中的20个字符Php 仅显示内容中的20个字符?显示段落?,php,mysql,Php,Mysql,我有另外一个问题需要帮助。我只想显示“内容”中的20个字符 <?php $output = ''; if(isset($_GET['q']) && $_GET['q'] !== ' ') { $searchq = $_GET['q']; $q = mysqli_query($db, "SELECT * FROM article WHERE title LIKE '%$searchq%' OR content LIKE
<?php
$output = '';
if(isset($_GET['q']) && $_GET['q'] !== ' ') {
$searchq = $_GET['q'];
$q = mysqli_query($db, "SELECT * FROM article WHERE title LIKE '%$searchq%' OR content LIKE '%$searchq%'") or die(mysqli_error());
$c = mysqli_num_rows($q);
if($c == 0) {
$output = 'No search results for <strong>"' . $searchq . '"</strong>';
} else {
while($row = mysqli_fetch_array($q)) {
$id = $row['id'];
$title = $row ['title'];
$content = $row ['content'];
$output .= '<a href="article.php?id=' .$id. '">
<h3>'.$title.'</h3></a>'.$content.'';
}
}
} else {
header("location: ./");
}
print("$output");
mysqli_close($db);
?>
我将回答你的第一个问题: 在以下内容后插入此行:
$content = $row ['content'];
if(strlen($content)>20) $content=substr ($content,0,19);
请注意:您的代码可能会受到sql注入黑客攻击。使用$searchq=mysqli_escape_string$_GET['q'];谢谢你回答第一个问题