如何从Atom Feed XML删除HTML标签

伊瑟贾姆

我为基于Laravel的博客准备了XML feed。当我检查它时,我的提要使用feedvalidator。我收到有关youtube嵌入式视频的错误:

line 24, column 0: content should not contain iframe tag (8 occurrences) [help]

我将我的提要放入控制器中:

public function index()
{   

    $data['posts'] = Post::orderBy('created_at', 'DESC')->->where('status',,1)-->limit(20)->get();


    return Response::view('rss',$data, 200, [
        'Content-Type' => 'application/xml; charset=UTF-8 ',
    ]);
}

我的Feed xml视图是:

{{ '<?xml version="1.0" encoding="utf-8" ?>' }}
<feed xmlns="http://www.w3.org/2005/Atom"
    xmlns:media="http://search.yahoo.com/mrss/">
    <link rel="self" type="application/atom+xml" href="http://sirtcantalilar.com/feed" />
    <title>Sirtcantalilar Topluluğu</title>
    <subtitle>Üzerinde Güneş Batmayan Topluluk</subtitle>
    <updated>{{ Carbon\Carbon::now()->toATOMString() }}</updated>
    <author>
        <name>Sırtçantalılar</name>
    </author>
    <id>tag:sirtcantalilar.com,{{date('Y-m-d')}}:/{{ Carbon\Carbon::now()->toATOMString() }}</id>

    @foreach($posts as $post)
        <entry>
            <author>
                <name>{{$post->author->name}}</name>
            </author>
            <title>{{ $post->title }}</title>
            <link rel="alternate" type="text/html" href="{{ URL::route('view-post', $post->slug) }}"/>
            <updated>{{$post->created_at->toATOMString() }}</updated>
            <id>{{ post_tag_uri($post)}}</id>
            @if(strlen($post->minicontent) > 0)
            <summary>{{$post->minicontent }}</summary>
            @else
            <summary>{{ Str::words(strip_tags(preg_replace("/&#?[a-z0-9]{2,8};/i","",$post->content)),13)}}</summary>
            @endif
            <content type="html"><![CDATA[{{$post->content}}]]></content>
             <category term="Blog"/>
              <content type="html"><{{nl2br($post->content)}}></content>
     </entry>
    @endforeach

</feed>

如何从内容中删除iframe?编辑1:我添加了此功能:

function rss_noiframe($content) {
    $content = preg_replace( '/<iframe(.*)\/iframe>/is', '', $content );

    return $content;
}

并尝试获得视图:

<content type="html"><![CDATA[{{rss_noiframe($post->content)}}]]></content>
伊瑟贾姆

对于那些想从这个问题中得到答案的人,我用以下代码解决了:

<content type="html"><![CDATA[{{preg_replace( '/<iframe(.*)\/iframe>/is', '', $post->content )}}]]></content>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章