Simple string passing thru URL

Discussion in 'PHP' started by iBold, Feb 8, 2007.

  1. #1
    Please keep in mind I'm a pretty big newb when it comes to this...

    I'm trying to pass a keyword through the URL into text onto a page of my site.
    Page URL example: www.example.com/index.php?kw=example
    I'm using this to do so:

    
    <?php
    $keyword = $_GET[’kw’];
    $keyword2 = $_GET[’kw’];
    $keyword = ucwords(str_replace("+"," ",$_GET[’kw’]));
    $keyword2 = ucwords(str_replace("+","_",$_GET[’kw’]));
    ?>
    
    Code (markup):
    Then to call it in the page, I'm using:
    
    <?php echo $keyword; ?>
    <?php echo $keyword2; ?>
    
    Code (markup):
    But my echo's refuse to show anything (just blank) instead of showing the word 'example' like they should from the URL above. I'm not getting any syntax errors, just nothing is displaying. Anyone able to tell me where I'm messing up? Thanks!
     
    iBold, Feb 8, 2007 IP
  2. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Those quotes inside the square brackets seem to be backquotes instead of single quotes?
     
    phper, Feb 8, 2007 IP
  3. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #3
    yeh phper i think you are right, because if they were single quotes, code should have worked.
     
    designcode, Feb 8, 2007 IP
  4. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    I tried your exact code and got the following errors:

    Notice: Use of undefined constant ’kw’ - assumed '’kw’' in [xxx]\get-test.php on line 4
    
    Notice: Undefined index: ’kw’ in [xxx]\get-test.php on line 4
    
    Notice: Use of undefined constant ’kw’ - assumed '’kw’' in [xxx]\get-test.php on line 5
    
    Notice: Undefined index: ’kw’ in [xxx]\get-test.php on line 5
    PHP:
    Changing the quotes will make it work.
     
    chopsticks, Feb 8, 2007 IP
  5. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #5
    Hey chopsticks, I can bet you are running PHP 5? Am I right?
     
    designcode, Feb 8, 2007 IP
  6. vishwaa

    vishwaa Well-Known Member

    Messages:
    271
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    138
    #6
    Echo the $_GET variable to see what things are exists in it. You may get an idea why it is not working.

    echo "<pre>";
    print_r($_GET);
    echo "</pre>";
    Code (markup):
     
    vishwaa, Feb 8, 2007 IP
  7. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #7
    as suggested it's backticks, replace them with quotation marks or inverted commas.
     
    krakjoe, Feb 9, 2007 IP
  8. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #8
    Nope: "PHP Version 4.3.2"
     
    chopsticks, Feb 9, 2007 IP
  9. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #9
    Ah ok, I thought u r using PHP 5. Sorry :)
     
    designcode, Feb 9, 2007 IP