Parse URI

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mtuller

    #1

    Parse URI

    I want to pull part of the URI out to dictate what is pulled from the
    database. For example, I want to control what year data is displayed
    with a url like this: http://www.mysite.com/display.php?year=2007

    I want to pull out the 2007. I can grab the uri, but what is the best
    way to pull out just the 2007?
  • badar.waqas@gmail.com

    #2
    Re: Parse URI

    On Nov 15, 10:34 am, mtuller <mitul...@gmail .comwrote:
    I want to pull part of the URI out to dictate what is pulled from the
    database. For example, I want to control what year data is displayed
    with a url like this:http://www.mysite.com/display.php?year=2007
    >
    I want to pull out the 2007. I can grab the uri, but what is the best
    way to pull out just the 2007?
    See parse and parse_url function in PHP manual.

    Comment

    • Rik Wasmus

      #3
      Re: Parse URI

      On Thu, 15 Nov 2007 06:34:37 +0100, mtuller <mituller@gmail .comwrote:
      I want to pull part of the URI out to dictate what is pulled from the
      database. For example, I want to control what year data is displayed
      with a url like this: http://www.mysite.com/display.php?year=2007
      >
      I want to pull out the 2007. I can grab the uri, but what is the best
      way to pull out just the 2007?

      $url = 'http://www.mysite.com/display.php?yea r=2007';
      $querystring = parse_url($url, PHP_URL_QUERY);
      $querydata = array();
      parse_str($quer ystring, $querydata);
      if(isset($query data['year'])) echo "Year is:".$querydat a['year'];

      --
      Rik Wasmus

      Comment

      • ZeldorBlat

        #4
        Re: Parse URI

        On Nov 15, 12:34 am, mtuller <mitul...@gmail .comwrote:
        I want to pull part of the URI out to dictate what is pulled from the
        database. For example, I want to control what year data is displayed
        with a url like this:http://www.mysite.com/display.php?year=2007
        >
        I want to pull out the 2007. I can grab the uri, but what is the best
        way to pull out just the 2007?
        Do you just have a URL in a string or is it the URL of the actual
        request? If it's the URL of the request, that value would be in:

        $_GET['year']

        If it's in a string the other solutions posted here should work.

        Comment

        • mtuller

          #5
          Re: Parse URI

          On Nov 15, 8:19 am, ZeldorBlat <zeldorb...@gma il.comwrote:
          On Nov 15, 12:34 am, mtuller <mitul...@gmail .comwrote:
          >
          I want to pull part of the URI out to dictate what is pulled from the
          database. For example, I want to control what year data is displayed
          with a url like this:http://www.mysite.com/display.php?year=2007
          >
          I want to pull out the 2007. I can grab the uri, but what is the best
          way to pull out just the 2007?
          >
          Do you just have a URL in a string or is it the URL of the actual
          request? If it's the URL of the request, that value would be in:
          >
          $_GET['year']
          >
          If it's in a string the other solutions posted here should work.
          Yes, it is the URL of the request. LOL I thought it would be harder
          than this. I was overthinking it. Thanks.

          Comment

          Working...