Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php to remove Rich text Styles

Shulou Source: shulou.com Published: 2022-06-03 10:41:44 10月02日 Update

This article will explain in detail how to use php to get rid of rich text styles, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Php to remove the rich text style method: 1, open the corresponding files in the project; 2, through the "function cutstr_html () {...}" method to remove all Html tag spaces; 3, call the "cutstr_html" method to remove the text style.

This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.

How does php get rid of rich text styles?

Php removes content formatting from rich text editors

In a new project, you need to display the first few lines of plain text in the article list page, because the background is the article added through a rich text editor, and the data returned directly is formatted data, resulting in confusion in the style of the list page. so you need to remove the format and return plain text data.

/ * * remove all Html tags, spaces and whitespace, and intercept the string (including Chinese) * @ param string $string string * @ param number $sublength string length * @ param string $encoding encoding * @ param string $ellipsis 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)). $ellipsis;}} / / Test string $str=' fherfhewkolfjlkdsjfld

'; / / call the method to test 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.

On how to use php to get rid of the rich text style to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Text style article character string content method data format more tag knowledge space article editor length project test good confusion Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Docker Huawei MariaDB Shulou Tech Info