Pls help me on string cuttting

Discussion in 'PHP' started by raiderremo, Sep 3, 2009.

  1. #1
    raiderremo, Sep 3, 2009 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    try
    $string = explode("?", $tmp);
    echo $string[0];
     
    bartolay13, Sep 3, 2009 IP
  3. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #3
    If it is for that specific string, do:

    
    $tmp = str_replace('?cat5','',$tmp);
    
    PHP:
    If you do not know what is after the ?, use preg_replace:

    
    $tmp = preg_replace('/\?(.*)/','',$tmp);
    
    PHP:
     
    ThePHPMaster, Sep 3, 2009 IP
  4. yuvrajm

    yuvrajm Peon

    Messages:
    52
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    definitely preg replace shall do the job!
     
    yuvrajm, Sep 4, 2009 IP
  5. SpamHat

    SpamHat Peon

    Messages:
    27
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I'd go with this if you just want to strip the URL variables.

    No need to use regex is there's.... no need :)
     
    SpamHat, Sep 4, 2009 IP
  6. basheer

    basheer Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    $string = explode("?", $tmp);
    echo $string[0];
    or
    $string=substr($tmp,strpos($tmp,"?")+1);
    echo $string;:cool:
     
    basheer, Sep 5, 2009 IP