开发者

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 stores something like this in database:

<p>Hello World</p>

When I retrieve from database, I would to extract each instance of

and add a class to it:

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

I think I got it to work:

    if ( ! funct开发者_JAVA百科ion_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;
    }
}


You can try a php parser like this one


Your problem is, that you use htmlspecialchars(). This changes it from HTML to plain text. Just remove this function call and it will be html code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜