preg_replace Array help

Discussion in 'PHP' started by Silver89, Jan 22, 2008.

  1. #1
    Hi,

    I'm just trying to get this working so they replace the correct item,

    So

    :) Would be replaced by <img src="/smilies/001_cool.gif" />
    ;) Would be replaced by <img src="/smilies/wink.gif" />
    (H) Would be replaced by <img src="/smilies/001_smile.gif" />


    $patterns = array
    (
    '/:\)/',
    '/;\)/',
    '/\(H\)/'
    );
    
    $replacements = array
    (
    '<img src="/smilies/001_cool.gif" />',
    '<img src="/smilies/wink.gif" />',
    '<img src="/smilies/001_smile.gif" />'
    );
    
    
    $comment = preg_replace($patterns, $replacements, $comment);
    PHP:
     
    Silver89, Jan 22, 2008 IP
  2. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #2
    You can use str_replace for that.

    $patterns = array
    (
    ':)',
    ';)',
    '(H)'
    );
    
    $replacements = array
    (
    '<img src="/smilies/001_cool.gif" />',
    '<img src="/smilies/wink.gif" />',
    '<img src="/smilies/001_smile.gif" />'
    );
    
    
    $comment = str_replace($patterns, $replacements, $comment);
    PHP:
     
    SoKickIt, Jan 22, 2008 IP
    Silver89 likes this.