Noob question -- Dynamic text?: index.php?keyword=test

Discussion in 'PHP' started by bradrx7, Sep 15, 2008.

  1. #1
    So I want to have dynamic text depending on the url. For example if the url is:

    www.mysite.com/index.php?variable=test

    I then want to have a page with a paragraph of text that has a variable. So everytime the website has $variable in the text, it replaces the $variable with test or whatever I specify in the URL. How do I do this and what is it called? I tried searching google for dynamic php text but I didnt find anything on how to actually do it. Thanks,
     
    bradrx7, Sep 15, 2008 IP
  2. ahowell

    ahowell Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    // www.mysite.com/index.php?variable=test
    
    if (array_key_exists('variable', $_GET)) {
        $variable = $_GET['variable'];
    }
    
    ?>
    
    <!-- your paragraph -->
    blah blah blah blah <?php echo $variable; ?>
    
    or
    
    blah blah blah blah <?=$variable?>
    PHP:
     
    ahowell, Sep 15, 2008 IP
  3. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #3
    Or you could do something like (1 line code):

    
    <?
    if (isset($_GET['variable']) echo $_GET['variable'];  // You may want to sanitize this var as it can lead to security holes.
    ?>
    PHP:
     
    nabz245, Sep 15, 2008 IP