tinymce在内容周围添加p标记并将其存储在数据库中,当我使用PHP检索时,分割p标记并向每个标记添加类的最佳方法是什


tinymce adds p tags around content and stores it in database, when I retrieve with PHP, what's best way to split the p tag and add a class to each

Tinymce在数据库中存储如下内容:

<p>Hello World</p>

当我从数据库中检索时,我将提取

的每个实例并向其添加一个类:

<p class='hello_world'>Hello World</p>

我想我成功了:

    if ( ! function_exists('tinymce_tag')){
    function tinymce_tag($content = ''){
        $pos = strpos($content, '<p>');
        if($pos !== false){
            $content = substr_replace($content,' class="paragraph"', 2, 0);
            return  $content;
        }
        return $content;
    }
}

您可以尝试像这样的php解析器

您的问题是,您使用htmlspecialchars()。这将它从HTML更改为纯文本。只要删除这个函数调用,它将是html代码。