Several methods for PHP to parse HTML strings _ PHP Tutorial

Source: Internet
Author: User
PHP processes several methods for parsing HTML strings. In the LieHuo. Net Tutorial, we often need to go to a substring in the html string. The following describes several methods for php to solve this problem: 1. strip_tags () function: can be filtered out. Tutorial on helping customers (www.Bkjia.com)We often need to go to a substring in the html string. The following describes several php methods to solve this problem:

1. strip_tags () function: filters out HTML and PHP tags and returns a brand new string!

Usage:

String strip_tags (string to be processed [, string tag to be retained])

For example, the tag is written in this way. strip_tags ($ str, ""). to keep multiple tags, use spaces to separate them.

2. mixed processing with strpos and substr

When the string we want to intercept has a unique identifier, we can usually use this method. for example, to obtain a tag abc with a unique id, you only need to find and, the contents in the middle are all displayed.

3. PHP DOMDocument

The method provided by DOMDocument is to output plain text without any labels. if you only need text data, this method is the easiest way to pull

Digest (LieHuo.. Net) in the tutorial, we often need to go to a substring in the html string. The following describes several php methods to solve this problem: 1. strip_tags () function: filter out...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.