Regular string replacement and partition function comparison in PHP

time:11-05-22 forum:PHP tools and code
  Reprinted from http://xuebingnanmm.iteye.com/blog/699901

this article introduces the differences between the regular regular matching functions of PHP, including str_replace, str_ireplace, substr_replace, preg_replace, preg_match, preg_match_all, preg_quote, preg_split, ereg_replace, preg_match, etc. Of course, a few of them can't use regular expressions, but because they are ambiguous in relation to the related regular functions, they can be put together for comparison.

name supports regular feature notes
str_replace X string substitution function, case sensitive
str_ireplace X string substitution function, case insensitive, support array batch replacement thanks to netizen Franci, remind add
substr_replace X part replace string function, can refer to Location is replaced by index

preg_replace Y specified matching mode, support substring reference is replaced by
ereg_replace Y specified matching mode, case sensitive, support substring reference
eregi_replace Y specifies matching mode to be replaced, case insensitive, support substring Reference

ereg Y specified pattern full text matching, can be used to match judgment, or return a matching array
preg_match Y to specify pattern matching one exit, can be used to match judgment, or use the returned matching array to specify mode full text matching with
preg_match_all Y. Use the matched array of returns to use

preg_split Y to specify a regular split in the matching mode, if it is best to use explode or str_split
str_split X to specify a length dissection string, by default a single character is divided into an array
explode X to specify a single or more. Character dissection string, the success returns an array, for example 12345 returns 12 and 5

preg_quote - canonical expression characters according to the 34 section, meaning the special character is added backslash, and the special characters of the regular expression include: *? [^] $() {} =!.lt;.Gt;.Gt;


Add:

1, there are two sets of regular expression library in PHP. The function is very similar:

a set is provided by POSIX (Portable Operating System) library, the function is named after the prefix, and the regular function library is no longer recommended.

is provided by PCRE (Perl Compatible Regular Expression) library. The function is named by preg_ prefix and recommended for priority use. In PCRE, mode expressions (i.e. regular expressions) are usually included between the two backslashes "/", such as "/^w $/" style.

2, PHP regular expression function: matching extraction, matching and replacement.

prev:PHP determines the character function co... next:Common JavaScript regular expressions in...
post comment
Notice



approved   Phoenix reporter Dunfee and others l...   BigDog big foot transport robot in t...   Go to Ji'nan Lantau Peak set (standa...   Reminder: handle the delivery proced...   Extreme sports - dogs can do it
rand   The solution to the problem of chaot...   PHP AJAX implements no refresh page ...   A summary of the method of generatin...   PHP paging code, suitable for use in...   Does the check directory exist and t...
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com