[英]CMS built with PHP/SQL : My post content is all in one paragrah with no space, how do I fix this?
這是我的問題。
我目前正在創建一個完全由PHP和SQL組成的博客。
我有要顯示在每個帖子中的內容,這些內容記錄在我的數據庫中。
到目前為止,這不是問題,因為我能夠輕松顯示每個帖子的內容。 但是,只有一個問題:所有內容都記錄到一個paragrah中,因此沒有空間。
通常,在每篇博客文章中,您都有多個paragrahs和空格,對嗎? 對我來說,所有事物都處在一種超現實狀態,這使事情看起來很難看。
這是我的PHP:
<?php
$query = "SELECT * FROM posts WHERE post_id = $the_post_id";
$select_posts = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($select_posts)){
$post_id = $row['post_id'];
$post_author = $row['post_author'];
$post_title = $row['post_title'];
$post_content = $row['post_content'];
$post_image = $row['post_image'];
$post_tags = $row['post_tags'];
$post_date = $row['post_date'];
?>
<article>
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-10 mx-auto">
<img src='postImages/<?php echo $post_image; ?>' style='width: 100%; height: 500px'>
<p><?php echo $post_content ?></p>
</div>
</div>
</div>
</article>
<?php } ?>
我該如何解決 ?
感謝所有回應
您應該使用該功能:
function nl2p($str) {
$arr=explode("\n",$str);
$out='';
for($i=0;$i<count($arr);$i++) {
if(strlen(trim($arr[$i]))>0)
$out.='<p>'.trim($arr[$i]).'</p>';
}
return $out;
}
它將每個\\ n(新行)替換為新段落並返回結果。 因此,將其放置在代碼中的某個位置,然后調用echo nl2p($ post_content);
從那里得到的功能: 如何用段落標簽包圍所有文本?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.