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.

strings

Discussion in 'PHP' started by siraxi, Sep 2, 2005.

  1. #1
    Hello

    I'm a PHP newbie... could anyone explain me how to change the string variable "Word1 Word2 Word3" into "word1+word2+word3" ? (stored in some variable named $string)

    I've never done this before, I could use some guiding.
    SEMrush
    Thanks!
     
    siraxi, Sep 2, 2005 IP
    SEMrush
  2. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #2
    from what i understand of your question, you've got a variable that contains text. this text consists of words separated with a single space. you want to replace the space with a "+" character.

    if so, you can use the str_replace function - e.g.

    $newstring = str_replace(" ", "+", $string);
     
    daboss, Sep 2, 2005 IP
  3. Connect

    Connect Guest

    Messages:
    191
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Notice it is converted lower case, might add in strtolower:

    $newstring = strtolower(str_replace(" ", "+", $string));
     
    Connect, Sep 2, 2005 IP
  4. siraxi

    siraxi Peon

    Messages:
    333
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you, guys!
     
    siraxi, Sep 2, 2005 IP