0

I was wondering if someone knows what the best method would be to extract a link from another link , Here's an example:

If I have links in the following format:

http://www.youtube.com/watch?v=35HBFeB4jYg OR http://it.answers.yahoo.com/question/index?qid=20080520042405AApM2Rv OR https://www.google.it/search?q=rap+tedesco&aq=f&oq=rap+tedesco&aqs=chrome.0.57j62l2.2287&sourceid=chrome&ie=UTF-8#hl=en&sclient=psy-ab&q=migliori+programatori&oq=migliori+programatori&gs_l=serp.3..0i19j0i13i30i19l3.9986.13880.0.14127.14.10.0.4.4.0.165.931.6j4.10.0...0.0...1c.1.7.psy-ab.tPmiWRyUVXA&pbx=1&bav=on.2,or.r_cp.r_qf.&fp=ffc0e9337f73a744&biw=1280&bih=699 

How would I go about extracting only the web pages like so:

http://www.youtube.com http://it.answers.yahoo.com https://www.google.it 

I was wondering if and what regular expression I could use with PHP to achieve this, also are regular expressions the way to go?

3 Answers 3

2

There is a PHP function for parsing URLs: parse_url

$url = 'http://it.answers.yahoo.com/question/index?qid=20080520042405AApM2Rv'; $p = parse_url($url); echo $p["scheme"] . "// . "$p["host"]; 
Sign up to request clarification or add additional context in comments.

Comments

1

Use function parse_url.

$link = "https://www.google.it/search?q=rap+tedesco"; $parseUrl = parse_url($link); $siteName = $parseUrl['scheme']."://". $parseUrl['host']; 

Using Regexp.

preg_match('@http(s?)://([\w]+\.){1}([\w]+\.?)+@',$link,$matches); echo $matches[0]; 

Codeviper Demo.

Comments

0

You just want to have the domain of the page, in PHP there exists a function called parse_url that could help

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.