php regex results in array to string conversion error -


i'm trying learn regex in php. why result in array string conversion error on last line , how fix it?

$document = "{title}this title{/title}"; preg_match("/{title}(.*){\/title}/", $document, $match);  echo $match; 

see this demo:

$document = "{title}this title{/title}"; preg_match("/{title}(.*){\/title}/", $document, $match); //echo $match; // php notice:  array string conversion in /home/jxkakh/prog.php on line 5 print_r($match); // => array(    [0] => {title}this title{/title}    [1] => title) 

see preg_match reference:

int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )
...
matches
if matches provided, filled results of search. $matches[0] contain text matched full pattern, $matches[1] have text matched first captured parenthesized subpattern, , on.

and pattern contains capture group defined (.*).


Comments