我试图从这个数组中获取信息,但出于某种原因,它将所有内容嵌套到 $matches[0]
中。
<?
$file = shell_exec('pdf2txt.py docs/April.pdf');
preg_match_all('/.../',$file,&$matches);
print_r($matches)
?>
这是否按预期工作?有没有办法将其放入深度为 1 的数组中?
编辑:
这是正则表达式:
([A-Z][a-z]+\s){1,5}\s?[^a-zA-Z\d\s:,.\'\"]\s?[A-Za-z+\W]+\s[\d]{1,2}\s[A-Z][a-z]+\s[\d]{4}
最佳答案
preg_match_all()
总是返回一个数组(如果成功,否则你会得到一个空数组),其中索引 0
包含一个数组,每个完整匹配都有一个元素,并且其他索引成为捕获组,每个匹配项都有一个内部数组。
这可能更容易理解......
array(2) {
[0]=>
array(2) {
[0]=>
string(12) "entire match"
[1]=>
string(32) "entire match matched second time"
}
[1]=>
array(2) {
[0]=>
string(15) "capturing group"
[1]=>
string(35) "capturing group matched second time"
}
}
关于php - Preg_match_all 返回数组中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6054442/