I have links of the following shape: http://website.com/stuff
and https://website.nl/stuff
. I would like to return the http/https part with the website name and domain. So for example, if I have
https://www.stackoverflow.com/questions/55823298/how-do-i-check-if-a-string-is-entirely-made-of-the-same-substring
I would like to return https://www.stackoverflow.com
.
if I have
http://www.website.nl/questions/55823298/how-do-i-check-if-a-string-is-entirely-made-of-the-same-substring
I would like to return http://www.website.nl
I now have this very basic code to achieve this:
<?php
$urlData = parse_url('https://www.stackoverflow.com/questions/55823298/how-do-i-check-if-a-string-is-entirely-made-of-the-same-substring');
echo "https://".$urlData['host'];
However, I would like that the code looks at the url and decide which prefix it should be, http
or https
. How can I achieve that?