Ask a question about getting a domain name from a website ~~~~~ I need to do this now. & nbsp; obtain its domain name from a bunch of URLs. for example, some URLs are saved in the database & nbsp; & nbsp; community. csdn. netExpertPostNew. asp? Room303 & nb ~~~~~
I need to do this now and get its domain name from a bunch of URLs.
For example, some URLs are stored in the database.
Http://community.csdn.net/Expert/PostNew.asp? Room = 303
Http://www.baidu.com? Lm = 0 & si = & rn = 10 & ie = gb2312
Http://www.taobao.com/browse/11/
...
To get his domain name from these URLs
Http://community.csdn.net
Http://www.baidu.com
Http://www.taobao.com
Expert guidance
------ Solution --------------------
String cutting
------ Solution --------------------
Take http: // to the next content.
------ Solution --------------------
Parse_url function
------ Solution --------------------
Cut "/"
Note:
Http://www.baidu.com
Split into three parts
That is
1. http:
2. empty string
3.www.baidu.com
------ Solution --------------------
$ S = 'http: // community.csdn.net/Expert/PostNew.asp? Room = 303
Http://www.baidu.com? Lm = 0 & si = & rn = 10 & ie = gb2312
Http://www.taobao.com/browse/11 ';
Preg_match_all ('/(http :\/\/.*?) \/.*? /I ', $ s, $ m );
Print_r ($ m [1]);