1

I haven URL-string like http://www.google.com/recaptcha/api/img/clean/logo.png, how can I extract only google.com from the URL? I want to do this on all my URL-strings.

user500468
  • 1,183
  • 6
  • 21
  • 36

2 Answers2

4

Try function parse_url()

<?php
$url =  'http://www.google.com/recaptcha/api/img/clean/logo.png';
$array = parse_url($url);

echo $array['host'];
Barif
  • 1,552
  • 3
  • 17
  • 28
1
<?php    
echo $_SERVER['SERVER_NAME'];
?>
asd
  • 138
  • 9
  • 1
    This isn't going to work as he I doubt he is running his script on googles' servers... – Darren Apr 03 '14 at 08:34
  • but why ou give me minus reputations ? the answer was correct! – asd Apr 03 '14 at 08:44
  • 1
    As you can see this answer doesn't have a negative score. Which means only one thing..... I didn't down vote your answer. And no, your answer is not correct to what the OP is asking. Sorry to be blunt but there it is. – Darren Apr 03 '14 at 08:47