- substr: documentation ( source)
- strpos: documentation ( source)
<?php
$roots = array('/www/dev/sites/www.fred-4.com',
'/www/dev/sites/www.fred-4.com-master');
foreach ($roots as $root) {
$key = substr($root, strpos($root, '.com'), 0, 1);
echo $root . " -> " . $key . PHP_EOL;
}