Hi is there a way to use str_replace to replace if find two values?

Discussion in 'PHP' started by macaela, Nov 24, 2011.

  1. #1
    hi is there a way of doing a str replace to look twice
    like at moment i have if find space replace with "-"
    PHP Code:
    Code: [Select]
     .str_replace(' ','-',($row['model']))  
    
    PHP:
    is there a way i can do if find twice
    $row['model
    if find space " " replace with "-" also if find "i30" replace with "10"
    is there a way i can try find another like if find " " replace with "-" also if find "130" replace with hello world??

    thanks in advance
     
    macaela, Nov 24, 2011 IP
  2. Archanos

    Archanos Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi, I guess you want something like:
    
    $find = array(' ', 'i30');
    $replace = array('-', '10');
    $result = str_replace($find, $replace, ($row['model']));
    
    PHP:
     
    Last edited: Nov 24, 2011
    Archanos, Nov 24, 2011 IP
  3. macaela

    macaela Active Member

    Messages:
    181
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks it works perfect.
     
    macaela, Nov 24, 2011 IP