/    Sign up×
Community /Pin to ProfileBookmark

select domain from a url

how can i select a domain from url? when url & domain is unknown.

ex: from [B][url]http://www.search.com/abcd.html[/url][/B] (url), how can i only select only [B][url]http://www.search.com[/url][/B](domain).

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 02.2006 — If it is the host name for the current document which you want, then you can use this:

$_SERVER["HTTP_HOST"]

The protocol being used is found here:

$_SERVER["SERVER_PROTOCOL"]
Copy linkTweet thisAlerts:
@moinuddin102authorNov 02.2006 — no it is not. i make a script who spider all url from current document. i wanted to take this domain names from collected/spidered urls.
Copy linkTweet thisAlerts:
@russellNov 02.2006 — can parse it out. see php [URL=http://us2.php.net/manual/en/function.strstr.php]string functions[/URL]
Copy linkTweet thisAlerts:
@moinuddin102authorNov 02.2006 — thanks for suggestion. but i have idea to make it. see thats and give me replied.

preg_match_all('/http://(.*)//Us', $string, $matches);

$values = $matches[1];

echo "<pre>";

print_r($values[0]);

echo "</pre>";

two days ago i applied here with another question. which answer is this. please suggest me about this. bye
Copy linkTweet thisAlerts:
@bokehNov 02.2006 — please suggest me about this. bye[/QUOTE]So what is supposed to happen if there is no trailing slash. And why are you using the "[I]s[/I]" flag? A domain shouldn't have line feeds in it.
Copy linkTweet thisAlerts:
@martin_arickyNov 03.2006 — This can be used to get the domain from url.

$url = "http://www.search.com/abcd.html";

$parts = parse_url($url);

echo $parts['scheme'] eg: http://

echo $parts['host']; eg: www.search.com // domain name

echo $parts['path']; eg : abcd.html


---------------------------------

Ricky Martin ?
×

Success!

Help @moinuddin102 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...