sam sam - 1 month ago 8
PHP Question

Is there a PHP function for retrieving the "first part" of a URL?

Is there a PHP function for retrieving the "first part" of a URL, similar to how

dirname
/
basename
act on file paths?

Something along the lines of

echo "url_basename('example.com/this_post/12312')"


which would return

example.com

Answer

parse_url should do this reliably.

Comments