'https://', 'www.' & all sub derictories reomve from a url with regex

PHP
<?php

    $url = "https:// http://www.app.azonedev.com/somet hing/nothi
    ng";
    $url_to_main_domain = preg_replace('/(https|http|:|\/\/|www.|\s)/i','',$url);
    $remove_sub_dir_from_url = preg_replace('/(\/).*/','',$url_to_main_domain);
    echo $remove_sub_dir_from_url;
Source

Also in PHP: