Home >Backend Development >PHP Tutorial >Several ways to parse HTML strings in PHP_PHP Tutorial
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