我有一个字符串,我想在一个数组中返回2个占位符,我该如何实现呢?
$text = 'is simply dummy text of the printing and [[file::aaa]] typesetting industry. Lorem Ipsum has been the [[file::bbb]] standard dummy text ever since the 1500s.';
if (preg_match("/\[\[.*\]\]/", $text, $matches)) {
print_r($matches);
}
答案 0 :(得分:1)
你可以尝试这样的事情:
if (preg_match_all("/\[\[(.*?)\]\]/", $text, $matches)) {
print_r($matches);
}
输出:
Array
(
[0] => Array
(
[0] => [[file::aaa]]
[1] => [[file::bbb]]
)
[1] => Array
(
[0] => file::aaa
[1] => file::bbb
)
)