How to use keyword of url as variable?

Discussion in 'PHP' started by TechMaster, Mar 18, 2010.

  1. #1
    I have a url as below....

    http://www.domain.com/keyword-abc/xyz.html

    I want to use keyword as variable. I have searched a lot to get it done but found nothing.

    any help?
     
    TechMaster, Mar 18, 2010 IP
  2. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #2
    This script has to work for your domain:

    
    preg_match('/(?P<keyword>\w+)-/', $_SERVER["REQUEST_URI"], $matches);
    
    $keyword = $matches["keyword"];
    
    echo($keyword);
    
    Code (markup):
     
    s_ruben, Mar 18, 2010 IP
  3. TechMaster

    TechMaster Peon

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    s_ruben@: Many Thanks for help, it is not working.
     
    Last edited: Mar 18, 2010
    TechMaster, Mar 18, 2010 IP
  4. s_ruben

    s_ruben Active Member

    Messages:
    735
    Likes Received:
    26
    Best Answers:
    1
    Trophy Points:
    78
    #4
    Can you write the full script and several urls.
     
    s_ruben, Mar 18, 2010 IP
  5. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #5
    I believe the OP would require mod-rewrite.
     
    danx10, Mar 18, 2010 IP
  6. Obi

    Obi Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I may be wrong. So may its code can help you?

    <html>
    <body>
    <?php
    $d=date("D");
    if ($d=="Mon")
    echo " Get ready for the week!";
    else
    echo "Have a good day!";
    ?>
    </body>
    </html>

    If I am wrong you can search at this web site: php tutorials.
     
    Obi, Mar 18, 2010 IP
  7. TechMaster

    TechMaster Peon

    Messages:
    225
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Thanks to all for the help. We got it done.
     
    TechMaster, Mar 18, 2010 IP