Preg_match_all returning an array in an array?

I am trying to get information from this array, but for some reason it is all nested in $matches[0].

<?

$file = shell_exec('pdf2txt.py docs/April.pdf');

preg_match_all('/.../',$file,&$matches);
print_r($matches)

?>

Does this work as intended? Is there any way to place this in an array of depth 1?

EDIT:

This is RegEx:

([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}
+5
source share
2 answers

preg_match_all()always returns an array (if successful, otherwise you get an empty array), where index 0contains an array with an element for each integer match, and the remaining indices become capture groups with an internal array for each match.

It might be easier to understand ...

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"
  }
}
+12
source

, ( "([A-Z] [a-z] +\s) {1,5}" ), $matches [1]. $matches [1] [0] .

preg_match_all docs, ( ), PREG_PATTERN_ORDER. , , $matches [0] - , , , $matches [1] , .

+1

All Articles