Help needed with "Parse error: syntax error, unexpected T_ELSE"

Discussion in 'PHP' started by BobC, Sep 19, 2010.

  1. #1
    Hi,

    I'm getting a parse error when I try and extend my php code. This is the it i have working ok so far:

    It inserts a keyword if one is used. Now I needed to remove hyphens so am trying to use this:

    but I get the parse error. I'm really no expert at this so if anyone could point out any errors I'd be very grateful. I need to insert a keyword when one is used, with a preceding word and remove any hyphens.

    Thanks
     
    BobC, Sep 19, 2010 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    this should work


    
    
    
    <?php
    if(isset($_GET['kw']))
    {
    $MainKeyWord=str_replace("-"," ",$_GET['kw']);
    echo ucwords( "preceding text".$MainKeyWord);
    }
    else 
    echo "Alternative text";
    ?> 
    
    
    
    PHP:
     
    kmap, Sep 19, 2010 IP
  3. BobC

    BobC Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Bloomin heck! That was fast!

    kmap, thanks very much, it works a treat now!

    But I realised just now after inserting it that I also need to strip out apostrophes if they are there. Is there a neat solution for that? If it was just the apostrophes I guess the $MainKeyWord would be along the lines of:

    but I'm unsure of how to do both the hypen and the apostrophes at the same time,

    thanks again for the rapid response :)
     
    BobC, Sep 19, 2010 IP