php 替换文本中的多个占位符 returns 1 个元素而不是 2 个
php replace multiple placeholders in text returns 1 element instead 2
我有一个字符串,我想 return 数组中的 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);
}
您可以尝试这样的操作:
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
)
)
我有一个字符串,我想 return 数组中的 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);
}
您可以尝试这样的操作:
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
)
)