faqts : Computers : Programming : Languages : PHP : Common Problems : URLs

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

115 of 143 people (80%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

what is URL

May 29th, 2002 08:17
Philip Olson, Kevin Nonya, reenu goerge,


URL literally stands for:

  Uniform Resource Locator

A generic URL is:

  http://www.example.com/dir/foo.php?fruit=apple&color=red

Let's use parse_url() to divide it up:

  $url = 'http://www.example.com/dir/foo.php?fruit=apple&color=red';
  $url_parts = parse_url($url);
  print_r($url);

Which results in:
  
  [scheme] => http
  [host]   => www.example.com
  [path]   => /dir/foo.php
  [query]  => fruit=apple&color=red

The meaning behind all this can be read about here:

  http://wombat.doc.ic.ac.uk/foldoc/foldoc.cgi?URL

PHP makes this information available in many ways, typically through 
various predefined variables.  For example:

  print $_SERVER['QUERY_STRING'];       // fruit=apple&color=red
  print $_GET['fruit'];                 // apple
  print basename($_SERVER['PHP_SELF']); // foo.php