preg_match_all('/\[(([^\]\[]*\[[^\]\[]*\])*|[^\]\[]*)\]/', 'fdaf [title] [subtitle] fdafa', $contents); $title = $contents[1][0]; $subtitle = $contents[1][1]; echo "