How to remove rich text style in php
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.
#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='<p style="microsoft yahei, arial; vertical-align: baseline; list-style-type: none; text-indent: 28px; line-height: 25px; text-align:center;margin-top: 12px; margin-bottom: 12px; padding: 0px; border: 0px; font-size: 14px;color:red;"> fherfhewkolfjlkdsjfld</p>'; //调用方法测试 echo cutstr_html($string=$str,$sublength=5,$encoding='utf-8',$ellipsis='...');
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
