Код: Выделить всё
# This file was autogenerated by Puppet [ wordpress::vhost ]
# Any manual edit to this file will be automatically removed
# ©2016, DevOps team
server {
listen 443 ssl;
root /var/www/as888;
index index.php;
server_name wptraining-sdemo.mysysweb.com;
......
......
Код: Выделить всё
$host_dir = '/etc/nginx/sites-enabled';
$_pattern = '/^.*server_name (.*);$/U';
$_clients = scandir($host_dir);
foreach ( $_clients as &$client ) {
if ( preg_match('/^as[0-9]{3}$/', $client, $matchs) ) {
$wp_domain = preg_replace($_pattern, "$1", file("{$host_dir}/{$matchs[0]}"));
echo "{$matchs[0]} => {$wp_domain[0]}";
}
}
< /code>
И я получаю самую 1 -ю строку файла в ответ: < /p>
as888 => # This file was autogenerated by Puppet [ wordpress::vhost ]
< /code>
Если я использую preg_grep < /code> вместо: < /p>
$wp_domain = preg_grep($_pattern, file("{$host_dir}/{$matchs[0]}"));
print_r($wp_domain);
< /code>
Я получаю что -то подобное: < /p>
Array
(
[10] => server_name wptraining-sdemo.mysysweb.com;
)
Что я делаю не так? И самое главное, что мне не хватает? Я не очень знаком с PHP и вроде как потерял в этом. Ни одна из постов/постов, не доступных в сети, не работала. По сути, что -то похожее на это: sed -n -e 's |^.*Server_name \ (.*\); $ | \ 1 | p' , я полагаю.
Любая помощь будет очень оценена. Лучший!
Подробнее здесь: https://stackoverflow.com/questions/410 ... irst-match
Мобильная версия