this demoを参照してください:
$document = "{title}this is the title{/title}";
preg_match("/{title}(.*){\/title}/", $document, $match);
//echo $match; // PHP Notice: Array to string conversion in /home/jxkaKh/prog.php on line 5
print_r($match);
// => Array( [0] => {title}this is the title{/title} [1] => this is the title)
はpreg_match
referenceを参照してください:
int preg_match (string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]])
...
matches
を matches
が提供されている場合、それは結果で満たされていますサーチ。 $matches[0]
は最初のキャプチャ括弧付きのサブパターンにマッチしたテキストを持つことになり、完全なパターンにマッチしたテキスト、$matches[1]
が含まれている、などます。
パターンには、(.*)
と定義されたキャプチャグループが含まれています。
'$ match'は配列で、' print_r($ match) 'を使用します –
また、学習目的のために、regexを使って遊ぶのに便利なツールと、PHPでどのように動作するかはhttp://www.phpliveregexです。 com –