1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Remove everything before ** in my string?

Discussion in 'PHP' started by Kerosene, Dec 20, 2007.

  1. #1
    $myvar will change, but will always have ** in it. I want to remove everything BEFORE and INCLUDING the **. How can I do this?

    $myvar = 'blablabla**keep_this';
    PHP:
    -----

    EDIT: ok i've worked it out, but I know I'm going the long way round... Can someone suggest something a little more elegant?

    $myvardelete = substr($myvar, 0, (stripos($myvar, "**")+2));
    $myvar = str_replace($myvardelete, '', $myvar);
    PHP:
     
    Kerosene, Dec 20, 2007 IP
  2. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Is it always going to have a constant # of characters at the back? If so, there is an easier way.
     
    tushardhoot1, Dec 20, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    
    $myvar = 'any string even if it contains &#($*% any characters, even ** strange right (its called magic)**keep_this';
    echo end(explode('**',$myvar));
    
    PHP:
    Peace,
     
    Barti1987, Dec 20, 2007 IP
  4. coderbari

    coderbari Well-Known Member

    Messages:
    3,168
    Likes Received:
    193
    Best Answers:
    0
    Trophy Points:
    135
    #4
    
    $myvar = 'blablabla**keep_this';
    echo substr($myvar, strripos($myvar,'**')+strlen('**'));
    
    PHP:
     
    coderbari, Dec 20, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    ^^ Why stripos() when we're not looking for an alphabetical character? (Note that stripos() is slower than strpos())
     
    nico_swd, Dec 21, 2007 IP