If $domain = apple.com, or mit.org.edu.au, how can I remove the '.com' and everything starting from the dot using PHP? e.g. apple.com becomes apple, mit.org.edu.au becomes mit (disregard www.).
If you already have the domain then simply explode the domain and take the first element of the array.
$domain = 'apple.com';
$domain_parts = explode('.', $domain);
echo $domain_parts[0]; // returns apple
Note that the above will not account for subdomains. I.e. 'www.apple.com' would return 'www'. But based on what you have asked above, explode may be adequate.
If you don't already have the domain then you can use PHP's parse_url function to extract the domain (host) from the URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With