我有这种形式的内容
$content ="<p>This is a sample text where {123456} and {7894560} ['These are samples']{145789}</p>";
我需要数组中大括号之间的所有值,如下所示:
array("0"=>"123456","1"=>"7894560","2"=>"145789")
我试过这段代码:
<?php
preg_match_all("/\{.*}\/s", $content, $matches);
?>
但我在这里获取从内容中第一个大括号到最后一个大括号的值。如何获得上述格式的数组?我知道我使用的模式是错误的。应该给出什么来获得上面显示的期望输出?
最佳答案
像这样...
<?php
$content ="<p>This is a sample text where {123456} and {7894560} ['These are samples']{145789}</p>";
preg_match_all('/{(.*?)}/', $content, $matches);
print_r(array_map('intval',$matches[1]));
输出:
Array
(
[0] => 123456
[1] => 7894560
[2] => 145789
)
关于php - 提取大括号正则表达式php之间的所有值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20838624/