Home >Backend Development >PHP Tutorial >Several ways to parse HTML strings in PHP_PHP Tutorial

Several ways to parse HTML strings in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-21 14:56:161001browse

 Bangkejia (www.Bkjia.com) tutorialOften we need to remove a certain substring in the html string. Here are some PHP methods to deal with such problems:

 1.strip_tags() function: can filter out HTML and PHP tags and return a brand new string!

Usage:

 string strip_tags (string string to be processed [, string tags to be retained])

For example: For tags, write it like this, strip_tags($str, “”). If you want to keep multiple tags, separate them with spaces.

2. Use strpos and substr for mixed processing

When the string we want to intercept has a unique identifier, we can usually use this method, such as taking a label abc with a unique id. As long as we find the and, all the content in the middle will come out.

 3.PHP DOMDocument

The method provided by DOMDocument is to output plain text without any tags. If you only need text data, this method is the easiest to use

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364252.htmlTechArticleLieHuo.Net tutorial often we need to remove a certain substring in the html string, as follows Several PHP methods to deal with such problems: 1.strip_tags() function: can filter out...
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