I would like to match all the patterns like [[WHATEVER]]
The text inside those two brackets can be uppercase or lowercase, it can start with space or end with space and can be made of two or more words separated by space
$string = "The [[QUICK]] brown [[FOX]] jumped over [[whatever]]";
parse $string; //I would like an result to be like array
array( 0 => "[[QUICK]]", 1 => "[[FOX]]", 2 => "[[whatever]]")
You can match them like this:
$re = "/\\[{2}.*?\\]{2}/";
$str = "The [[QUICK]] brown [[FOX]] jumped over [[whatever]]";
preg_match_all($re, $str, $matches);
print_r($matches[0]);
Output of a sample program:
Array
(
[0] => [[QUICK]]
[1] => [[FOX]]
[2] => [[whatever]]
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With