- preg_match: documentation ( source)
- var_export: documentation ( source)
- explode: documentation ( source)
<?php
$output = 'tag: 7.x-2.x-1511112-53-combined
tag: 7.x-2.x-1511112-50-static-cache-per-git-dir
HEAD, tag: xxxx, origin/HEAD, origin/7.x-2.x, 7.x-2.x
tag: 7.x-3.0--alpha5
tag: 7.x-2.2
tag: 7.x-2.1
tag: 7.x-2.0';
$lines = explode("\n", $output);
$tag = NULL;
foreach ($lines as $line) {
$parts = explode(', ', $line);
foreach ($parts as $part) {
if (preg_match('/^tag: (\d+\.x\-\d+\.\d+(?:|\-\w+\d+))$/', $part, $m)) {
$tag = $m[1];
break 2;
}
}
}
var_export($tag);