Home Backend Development PHP Problem How to remove rich text style in php

How to remove rich text style in php

Sep 20, 2021 am 10:42 AM
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.

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),&#39;utf-8&#39;) < $sublength){
         return trim($string).$ellipsis;
 }else{
         return mb_strcut(trim($string),0,$sublength,$encoding).$ellipsis;
 }}//测试字符串
 $str=&#39;<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>&#39;;
 //调用方法测试
 echo cutstr_html($string=$str,$sublength=5,$encoding=&#39;utf-8&#39;,$ellipsis=&#39;...&#39;);
Copy after login

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

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

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

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

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

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

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

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

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

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

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

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

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

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

See all articles