- var_dump: documentation ( source)
- array_column: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$text = "[text]
(more text)
(text...)
[text!]
(last text)";
preg_match_all('/[\[\(](.*?)[\]\)]/', $text, $matches, PREG_SET_ORDER, 0);
$texts = array_column($matches, 1);
var_dump($texts);