Fast three source download "Word Fairy Source Forum" hxforum.com "Papaya Source Forum" papayabbs.com Enterprise E 2952777280
/** "Word Fairy Source Forum" hxforum.com "Papaya Source Forum" papayabbs.com Enterprise E 2952777280
- Modifier
- I Case-Insensitive search
- G Find all occurrences (global search)
- M as a multiline default ^ $ as the start and end of each line using the M modifier will ^ and $ match the start portion of each line
- S regards a string as a line ignoring the line break
- X ignores whitespace and annotations in regular expressions
- U stop after first match
- Metacharacters
- \a Match with Kai ou
- \b Match Boundary
- \b matches any character except the bounds such as/sa\b/and tail cannot appear SA
- \d matching numeric characters [0-9]
- \d matches non-numeric
- \s matching whitespace characters
- \s matches non-whitespace characters
- [] character class
- () a grouping of characters
- $ Match Line End
- ^ Match beginning of Line
- . Match any character other than line break
- \ leads to the next character
- \w matches underscores and numbers, letters
- \w match non-underlined alphanumeric
*/
Search arrays
$foods = Array ("Pass", "Port", "pad");
$food = Preg_grep ("/^p/i", $foods);//Match with the beginning of the character array I represents ignoring case
Var_dump ($food);//array (3) {[0]=> string (4) "Pass" [1]=> string (4) "Port" [2]=> string (3) "Pad"}
Search string
$string = "I hava a beautiful gift,do you want has a same one gift?";
$matchs = Preg_match ("/\bgift\b/i", $string, $MARCT);//Match if gift return bool value is case insensitive
Var_dump ($MATCHS);
Var_dump ($MARCT);
Matches all occurrences of a string
$userinfo = "<b>nanme</b><br> send <b>class</b>";
$res =preg_match_all ("/<b> (. *) <\/b>/u", $userinfo, $result);
Var_dump ($result [0][0]);
Var_dump ($result [0][1]);
Echo $res; Shows the number of matches obtained
Directed match substitution will be replaced with gift
$string = "I hava a beautiful gift,do you want has a same one gift?";
$re = Preg_replace ("/gift/i", "smell", $string);
Echo $re;
Do not pass a regular-style substitution
$key = Array ("/beautiful/", '/you/');
$res = Array (' beautiful ' = "Wonderful", "you" = "Me");
Echo preg_replace ($key, $res, $string);
Replace the matched string with a callback function
Preg_replace_callback ($key, $callback, $re)//$key regular $re closure function $re Input string $callback closure function
Show the number of identical characters
$str 1 = "abc2d";
$str 2 = "Bcd1 ASD";
Echo strspn ($str 2, $str 1);//3
Just the beginning of the first character uppercase
Echo Ucfirst ($str 2);
Capitalize the first letter of each word
Echo Ucwords ($str 2); BCD1 ASD
Htmlspecialchars ($string) converts a special symbol into a symbol table
/**
- & &
- ""
- ' & #039
- < <
- > &QT
*/
$strs = "$strs = Htmlspecialchars ($strs); does not output HTML format
Var_dump ($strs);
Fast three source download PHP perl style Common use of regular expressions