PHP uses regular expressions to extract the characters in the string with angle brackets <>, parentheses (), brackets [], curly braces {} Descriptor examples, the friends you need can refer to the following
The code is as follows:
$str = "Hello <我> (Love) [Beijing]{Tiananmen Square}";
Echo F1 ($STR); Back to Hello
echo F2 ($STR); Return to my
echo f3 ($STR); Return to Love
echo f4 ($STR); Back 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_match_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 ();
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) means that this character is not captured. It seems PHP does not support converting characters to parentheses.
Otherwise you can put a look into the nest, you can loop matching.
PS2: Surround: (?!) (?=) (?
There is a less than sign on the right side of the match, no match on the left. An exclamation point is unequal, and an equal sign represents equality.
PS3: Verified by authenticator, see Resources for Validator.
http://www.bkjia.com/PHPjc/750625.html www.bkjia.com true http://www.bkjia.com/PHPjc/750625.html techarticle PHP uses regular expressions to extract strings of angle brackets, parentheses (), brackets [], curly braces {} In the Word descriptor example, the need for friends can refer to the following code: $STR = Hello i (Love) [Beijing ...]