problem with str_replace()

Discussion in 'PHP' started by avlisodraude, Jun 25, 2008.

  1. #1
    I have a problem with str_replace():

    when I try to use it in this way:

    $phrase = "INSERT INTO addressbook(user_id, email, name) VALUES( 10 , 4 , 0 ) ON DUPLICATE KEY UPDATE(user_id= 10 )";
    $healthy = array("10","4","0");
    $yummy = array("FLA",".0797",".0700");

    $newphrase = str_replace($healthy, $yummy, $phrase);
    echo 'www: '.$newphrase;


    Instead of getting what I would expected:

    INSERT INTO addressbook(user_id, email, name) VALUES( FLA , .0797 , .0700 ) ON DUPLICATE KEY UPDATE(user_id= FLA )

    I get this:

    INSERT INTO addressbook(user_id, email, name) VALUES( FLA , ..0700797 , .0700 ) ON DUPLICATE KEY UPDATE(user_id= FLA )

    could someone please tell me what is the mistake or error?

    thanks in advance
     
    avlisodraude, Jun 25, 2008 IP
  2. rile

    rile Member

    Messages:
    77
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    First 10 is replaced with FLA, then 4 with .0797, then both 0 are replaced with .0700.

    Make something like this:
    $phrase = "INSERT INTO addressbook(user_id, email, name) VALUES( {user_id},{email},{name}) ON DUPLICATE KEY UPDATE(user_id= 10 )";
    $healthy = array("{user_id}","{email}","{name}");
    $yummy = array("FLA",".0797",".0700");
     
    rile, Jun 25, 2008 IP