[email protected] wrote:
Hello NYPHP,

I am using preg_replace to try to extract the domain name of one of my
sites so that I can use it as a variable. It has a standard http
format, i.e. http://www.mydomain.com and I am trying to get only
"mydomain" from it.

I have something that works but it does multiple tests before it
generates the variable I need. I thinking that the multiple lines
ought to be combined into a single statement that does the job on one
fell swoop. Am I right in assuming this can be done in one line of
code?

TIA for any pointers.


Use parse_url()

http://us3.php.net/parse_url


Something like this:

$domain = parse_url($my_url, PHP_URL_HOST);


Or, if you want some of the other pieces later:

$chunks = parse_url($my_url);
$domain = $chunks['host'];

// then you can use 'path', 'query', etc. as well.


--
justin
http://justinhileman.com

_______________________________________________
New York PHP User Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/show_participation.php

Reply via email to