Request_uri ....if else

Discussion in 'PHP' started by sfumato, May 1, 2012.

  1. #1
    Hello,

    I was wondering if I can put an if else, I just cannot get it to work.
    The problem is that strpos() return FALSE when it doesn't find '?' in $request_uri. and it returns empty string.

    <?php
    $request_uri = $_SERVER['REQUEST_URI'];

    // find position of '?' in a string
    $position = strpos($request_uri, 0, '?');

    // take out part of string
    $path = substr($request_uri, 0, $position);

    // form url
    $url = 'http://www.mysite.com'.$path.'?';
    ?>

    This is my url:
    <?php echo $url?>jr_listings=bed-and-breakfasts

    I was wondering if there it was possible to put and if and }else{ so that if there is no '?' in the request_uri, then I still get the request_uri string.

    I have been working on this all day and just cannot get it to work :confused:
     
    sfumato, May 1, 2012 IP
  2. goldenretriever

    goldenretriever Peon

    Messages:
    14
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    There are easier ways to break down a URL, such as parse_url().
    With that said, you can create conditionals in this form:
    $position=( ($c=strpos($request_uri,0,"?")!="")?$c:strlen($request_uri);

    This will require some modification, pending how strpos() acts.
     
    goldenretriever, May 6, 2012 IP