提取大括号正则表达式php之间的所有值
发布时间:2020-12-13 22:56:30 所属栏目:百科 来源:网络整理
导读:我有这个表格的内容 $content ="pThis is a sample text where {123456} and {7894560} ['These are samples']{145789}/p"; 我需要数组中的大括号之间的所有值,如下所示: array("0"="123456","1"="7894560","2"="145789") 我试过这个代码: ?phppreg_match_
我有这个表格的内容
$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('/{(.*?)}/',$matches); print_r(array_map('intval',$matches[1])); 输出: Array ( [0] => 123456 [1] => 7894560 [2] => 145789 ) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |