php uses regular expressions to extract the characters descriptor in a string with angle brackets <>, parentheses (), brackets [], curly braces {}, and a friend in need can refer to the following
Code as follows: $str = "Hello < i > (love) [Beijing]{Tiananmen}"; echo F1 ($STR); Back to Hello echo f2 ($STR); Return me echo f3 ($STR); Back to Love echo f4 ($STR); Return to Beijing echo f5 ($STR); Back to Tiananmen function F1 ($str) { $result = Array (); Preg_match_all ("/^ (. *) (?:<)/I", $STR, $ Result); return $result [1][0]; } function F2 ($str) { $result = Array (); preg_m Atch_all ("/(?:<) (. *) (?:>)/I", $str, $result); return $result [1][0]; } function F3 ($STR) { $result = Array (); Preg_match_all ("/(?:() (.*) (?:)) /i ", $str, $result); return $result [1][0]; } function f4 ($str) { $result = Array (); &N Bsp Preg_match_all ("/(): [) (. *) (?:])/I", $str, $result); return $result [1][0]; } function f5 ($STR) { $result = Array (); Preg_match_all ("/(?: {) (. *) (?:})/I", $str, $result); return $result [1][0]; } PS: (?: character) indicates that this character is not captured. It seems that PHP does not support converting characters to parentheses. Otherwise you can insert a glance around it and you can loop through it. PS2: Look around: (?!) (?=) (? <!) (? <=) has a less than match on the right side, no match on the left. Exclamation marks are unequal, equals numbers represent equality. PS3: Verified by validator, see Resources for Validator.