One solution that would cover for more cases would be based on sed regexps:
echo http://example.com/index.php | sed -e 's#^https://\|^http://##' -e 's#:.*##' -e 's#/.*##'
That would work for URLs like:
http://example.com/index.php, http://example.com:4040/index.php, https://example.com/index.php