What are some common methods for retrieving the subdomain name in PHP?
To retrieve the subdomain name in PHP, you can use the $_SERVER['HTTP_HOST'] variable to get the full domain name, then extract the subdomain from it. One common method is to explode the domain name by dots and retrieve the first part as the subdomain. Another method is to use regular expressions to match the subdomain part of the domain name.
$host = $_SERVER['HTTP_HOST'];
$subdomain = explode('.', $host)[0];
echo $subdomain;
```
```php
$host = $_SERVER['HTTP_HOST'];
preg_match('/([a-z0-9-]+)\.domain\.com/', $host, $matches);
$subdomain = $matches[1];
echo $subdomain;