PHP string regular expression replacement function preg_replace instructions for use _ PHP Tutorial

Source: Internet
Author: User
Tags ereg
Use the PHP string regular expression replacement function preg_replace. 1. preg_replace () $ msgpreg_replace (style. + styleis, $ msg); ----- delete stylestyle and the middle part $ msgpreg_replace ([^] +, $ msg); ----- is the delete and inner 1. preg_replace ()

$ Msg = preg_replace ("/ And the middle part
$ Msg = preg_replace ("/<[^>] +>/", "", $ msg); ----- delete <> and intermediate content

I (PCRE_CASELESS)
If this modifier is set, characters in the mode match both uppercase and lowercase letters.
S (PCRE_DOTALL)
If this modifier is set, the DOT metacharacters (.) in the pattern match all characters, including line breaks. If this parameter is not set, line breaks are not included. This is equivalent to the/s modifier of Perl. For example, [^ a] always matches a line break, regardless of whether this modifier is set.


2. ereg () and eregi ()

Note: The preg_match () function is usually a faster alternative than ereg ().

Eregi (" ] +)> (. +)", $ Data, $ B) ---- check whether the $ data contains the body tag. If yes, assign $ B [0] to the parameter and $ B [1] to the intermediate part.

Bool ereg (string pattern, string [, array regs])

Int eregi (string pattern, string, array [regs])

Eregi () and ereg () are similar in usage. The difference is that ereg () is case sensitive, and eregi () is not case sensitive.

Http://www.bkjia.com/PHPjc/323817.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323817.htmlTechArticle1. preg_replace () $ msg = preg_replace ("/style. + \/style/is "," ", $ msg); ----- delete the style/style and the middle part $ msg = preg_replace ("/[^] + /", "", $ msg); ----- is in the middle of the delete and...

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.