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.

str_replace not working

Discussion in 'PHP' started by sam1, Jan 4, 2007.

  1. #1
    I am stuck into a strange problem.
    I am running php5 on apache.
    and the problem is that str_replace command is not working

    $name="mike stemle";
    str_replace("mike","kite",$name);
    echo $name.

    Output should be 'kite stemle'
    but strange, for me the output is still "mike stemle"

    Am i making some mistake??
     
    sam1, Jan 4, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $name = str_replace("mike","kite",$name);
    
    PHP:
    str_replace() returns the new value and you have to assign it to a variable.
     
    nico_swd, Jan 4, 2007 IP
  3. YIAM

    YIAM Notable Member

    Messages:
    2,480
    Likes Received:
    240
    Best Answers:
    0
    Trophy Points:
    280
    #3
    This will solve your problem:

    $name="mike stemle";
    $name=str_replace("mike","kite",$name);
    echo $name.
     
    YIAM, Jan 4, 2007 IP
    sam1 and sundaybrew like this.
  4. sam1

    sam1 Active Member

    Messages:
    679
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    58
    #4
    oh my goodness!!

    I am so stupid..
    Thanks nico_swd and yiam. Green your way
    Sorry nico system is not allowing me to give you green. As i gave u green 2-3 days before also. Anyway thanks man :)
     
    sam1, Jan 4, 2007 IP
    YIAM likes this.
  5. weknowtheworld

    weknowtheworld Guest

    Messages:
    306
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Please write following code :

    $name="mike stemle";
    echo str_replace("mike","kite",$name);
     
    weknowtheworld, Jan 5, 2007 IP
  6. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i hate it when it is a really obvious fix.
    ANd for some reason I can never see it
     
    bobby9101, Jan 5, 2007 IP
  7. Poon Poi Ming

    Poon Poi Ming Active Member

    Messages:
    163
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Hi, the funny thing is I did not make the above mistake and yet, str_replace is not working:

    $pt_old = $this->text('title');
    $pt_new=str_replace("a", " ", $pt_old);
     
    Poon Poi Ming, Nov 24, 2012 IP