Laravel:如何让 CKEditor 显示 post 正文的前几个字而不改变其他 post 的样式
Laravel: How to get CKEditor to display first few words of post body without altering the styling of other posts
我正在制作一个 Laravel 项目,该项目需要使用我网站上的 CKEditor 将数据写入数据库并从数据库中检索数据。它相应地显示 posts,所以检索没有问题,我能够 trim 每个所以前几个词显示(因为那时我希望人们点击 posts并在各自的页面上阅读它们)但是来自 CKEditor 的 HTML 合并并编辑了其他根本没有任何样式的 post(在本例中是删除线文本)。
IMAGE 1: what happens to other posts thanks to post 4
IMAGE 2: what the other posts should look like because they have no styling
IMAGE 3: what post 4 fully says
我真正想要的是每个 post 的第一个单词甚至行显示,同时保留 CKEditor 制作的格式(例如包括斜体和粗体)。
有什么办法吗?谢谢:)
INDEX.BLADE.PHP
@extends('layouts/app')
@section('content')
<h1>Posts</h1>
@if(count($posts)>0)
@foreach($posts as $post)
<?php
$string = html_entity_decode($post->body);
?>
<div class="well">
<h3><a href="/posts/{{$post->id}}">{{$post->title}}</a></h3>
<p>{!!Str::words($string, 7, '...')!!}</p>
<small>{{$post->created_at}}</small>
</div>
<br/>
@endforeach
{{$posts->links()}}
@else
<h4>NO POSTS FOUND :(</h4>
@endif
@endsection
试试这个-
{{ Str::limit($post->body, 7) }}
对于CKEditor-
{!! Str::limit($post->body, 7) !!}
我正在制作一个 Laravel 项目,该项目需要使用我网站上的 CKEditor 将数据写入数据库并从数据库中检索数据。它相应地显示 posts,所以检索没有问题,我能够 trim 每个所以前几个词显示(因为那时我希望人们点击 posts并在各自的页面上阅读它们)但是来自 CKEditor 的 HTML 合并并编辑了其他根本没有任何样式的 post(在本例中是删除线文本)。
IMAGE 1: what happens to other posts thanks to post 4
IMAGE 2: what the other posts should look like because they have no styling
IMAGE 3: what post 4 fully says
我真正想要的是每个 post 的第一个单词甚至行显示,同时保留 CKEditor 制作的格式(例如包括斜体和粗体)。
有什么办法吗?谢谢:)
INDEX.BLADE.PHP
@extends('layouts/app')
@section('content')
<h1>Posts</h1>
@if(count($posts)>0)
@foreach($posts as $post)
<?php
$string = html_entity_decode($post->body);
?>
<div class="well">
<h3><a href="/posts/{{$post->id}}">{{$post->title}}</a></h3>
<p>{!!Str::words($string, 7, '...')!!}</p>
<small>{{$post->created_at}}</small>
</div>
<br/>
@endforeach
{{$posts->links()}}
@else
<h4>NO POSTS FOUND :(</h4>
@endif
@endsection
试试这个-
{{ Str::limit($post->body, 7) }}
对于CKEditor-
{!! Str::limit($post->body, 7) !!}