Home  >  Article  >  Backend Development  >  Instructions for using PHP string regular replacement function preg_replace

Instructions for using PHP string regular replacement function preg_replace

高洛峰
高洛峰Original
2017-01-20 09:35:351278browse

1. preg_replace()

$msg = preg_replace("/ and the middle part
$msg = preg_replace("/<[^>]+>/", "", $msg); ----- is to delete <> and the content in between

i (PCRE_CASELESS)
If this modifier is set, the characters in the pattern will match both uppercase and lowercase letters.
s (PCRE_DOTALL)
If this modifier is set, the dot metacharacter (.) in the pattern matches all characters, including newlines. Without this setting, newline characters are not included. This is equivalent to Perl's /s modifier. Excluded character classes such as [^a] always match newlines, 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 there is a body tag in $data. If so, assign the parameter $b[0] and the middle part $b[1].

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

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

eregi() and ereg() is similar and has the same usage. The difference is that ereg() is case-sensitive, while eregi() is case-independent.

For more PHP string regular replacement function preg_replace usage instructions and related articles, please pay attention to the PHP Chinese website!

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