Home>Article>Backend Development> How to remove rich text style in php

How to remove rich text style in php

藏色散人
藏色散人 Original
2021-09-20 10:42:03 2695browse

How to remove rich text style in php: 1. Open the corresponding file in the project; 2. Use the "function cutstr_html(){...}" method to remove all Html tag spaces; 3. Call "cutstr_html ” method can be used to remove text styles.

How to remove rich text style in php

#The operating environment of this article: Windows7 system, PHP7.1, Dell G3 computer.

How to remove rich text style in php?

php remove content formatting in rich text editor

##In a new project, I encounter the need to display the first few lines of plain text of the article content on the article list page. Because the background is an article added through a rich text editor, the data returned directly is formatted data, resulting in a list The page style is confusing, so the formatting needs to be removed to return plain text data.

/** * 去除Html所有标签、空格以及空白,并截取字符串(包括中文) * @param string $string 字符串 * @param number $sublength 字符串长度 * @param string $encoding 编码方式 * @param string $ellipsis 省略号 */ function cutstr_html($string,$sublength,$encoding = 'utf-8',$ellipsis = '…'){$string = strip_tags($string); $string = trim($string); $string = mb_ereg_replace("\t","",$string); $string = mb_ereg_replace("\r\n","",$string); $string = mb_ereg_replace("\r","",$string); $string = mb_ereg_replace("\n","",$string); $string = mb_ereg_replace(" ","",$string); if(mb_strlen(trim($string),'utf-8') < $sublength){ return trim($string).$ellipsis; }else{ return mb_strcut(trim($string),0,$sublength,$encoding).$ellipsis; }}//测试字符串 $str='

fherfhewkolfjlkdsjfld

'; //调用方法测试 echo cutstr_html($string=$str,$sublength=5,$encoding='utf-8',$ellipsis='...');

The output is a plain text string of length 5, which can be displayed in the article list.

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of How to remove rich text style in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn