Php 从使用Fusion Builder的wordpress中剥离HTML和短代码

Php 从使用Fusion Builder的wordpress中剥离HTML和短代码,php,wordpress,Php,Wordpress,首先,我正在使用Wordpress>Avada主题>和Fusion核心插件 我想做的是将任何帖子的内容缩减到几个字符。我所做的几乎适用于所有内容,除了使用Fusion核心插件的帖子内容 下面是我的函数,它应该获取摘录并缩小它 function get_my_excerpt_by_id($post_id, $length, $strip_html) { if(!$length) $excerpt_length = 35; else

首先,我正在使用Wordpress>Avada主题>和Fusion核心插件

我想做的是将任何帖子的内容缩减到几个字符。我所做的几乎适用于所有内容,除了使用Fusion核心插件的帖子内容

下面是我的函数,它应该获取摘录并缩小它

function get_my_excerpt_by_id($post_id, $length, $strip_html)
{   
    if(!$length)        
      $excerpt_length = 35;     
    else        
      $excerpt_length = $length;

    if(!isset($strip_html) || $strip_html == true)      
      $strip_html = true;

    $the_post = get_post($post_id); //Gets post ID
    $the_excerpt = apply_filters('the_content',$the_post->post_content); //Gets post_content to be used as a basis for the excerpt

    if($strip_html == true)
        $the_excerpt = strip_tags(strip_shortcodes($the_excerpt)); //Strips tags and images

    $words = explode(' ', $the_excerpt, $excerpt_length + 1);

    if(count($words) > $excerpt_length) :
        array_pop($words);
        array_push($words, '…');
        $the_excerpt = implode(' ', $words);
    endif;

    return $the_excerpt; 
}
所以这就像一个魅力,除非我使用Fusion Core插件作为一个帖子类型,因为我得到了这个

“.fusion-fullwidth-4{左填充:0px!重要;…”

你知道为什么不剥离短代码、css和html吗?尽管在看它的时候,可能只是css?那就留下来了。谢谢

编辑::
原来只是css保留了下来。所以现在我必须弄清楚如何删除它们。一段时间后的所有内容…

将样式标记添加到条带标记中

$the_excerpt = strip_tags(strip_shortcodes($the_excerpt), '<style>'); //add tags like
$the_extract=strip_标记(strip_短代码($the_extract),“”);//添加如下标记

我希望这能解决问题。

我只是想把我的答案贴在这里,以防以后有人需要它,谢谢古拉姆·阿里对我的答案的帮助

因此,当使用Fusion Core时,它会添加
标记,当使用strip_标记移除时,会将css代码嵌套在标记中

因此,为了解决这个问题,我们首先使用

$the_extract=strip_标记(strip_短码($the_extract),“”);

然后,我们用这个漂亮的正则表达式去掉
标记及其内容(我没有写,但不知道如何给写过的人正确的评价)

$the_extract=preg_replace(“|]*>(.*?|s“,”,$the_extract);

这是我用来获取内容并输出摘录的完整功能。我希望这对某些人有用

function get_my_excerpt_by_id($post_id, $length, $strip_html){
    if(!$length)
        $excerpt_length = 35;
    else
        $excerpt_length = $length;

    if(!isset($strip_html) || $strip_html == true)
        $strip_html = true;

    $the_post = get_post($post_id); //Gets post ID
    $the_excerpt = apply_filters('the_content',$the_post->post_content);//$the_post->post_content); //Gets post_content to be used as a basis for the excerpt

    if($strip_html == true)
    {
        $the_excerpt = strip_tags(strip_shortcodes($the_excerpt), '<style>');
        $the_excerpt = preg_replace("|<style\b[^>]*>(.*?)</style>|s", "", $the_excerpt);
    }

    $words = explode(' ', $the_excerpt, $excerpt_length + 1);

    if(count($words) > $excerpt_length) :
        array_pop($words);
        array_push($words, '…');
        $the_excerpt = implode(' ', $words);
    endif;

    return $the_excerpt;
}
函数get_my_extract_by_id($post_id,$length,$strip_html){
如果(!$length)
$extract_length=35;
其他的
$extract_length=$length;
如果(!isset($strip_html)|$strip_html==true)
$strip_html=true;
$the_post=get_post($post_id);//获取post id
$the_extract=apply_filters('the_content',$the_post->post_content);//$the_post->post_content);//获取要用作摘录基础的post_内容
如果($strip\u html==true)
{
$the_extract=strip_标签(strip_短码($the_extract),“”);
$the|u extract=preg_replace(“|]*>(.*?|s)”,“”,$the|u extract);
}
$words=explode(“”,$the_extract,$extract_length+1);
如果(计数($words)>摘录长度):
数组_pop($words);
数组推送($words,“…”);
$the_摘录=内爆(“”,$words);
endif;
返回$U摘录;
}

这就是strip\u标记的实际工作方式。上面的标记是允许的标记,因此这些标记将被跳过。但是感谢您花时间尝试帮助我。是否要从内容中删除短代码。您是否尝试过preg\u replace函数?当更改以获取内容时,我根本不返回任何内容。这有什么区别吗?i have没有尝试过preg_replace,现在正在查找。但我真的只想删除css。短代码似乎已被删除。内容将返回echo,而get_内容将不返回echo。我以前使用过相同的函数,将删除所有标记,短代码,