Need Help with Regex Related Function

Discussion in 'PHP' started by arpit13, Dec 2, 2011.

  1. #1
    Hello,

    i am stuck at making a emoticon system for my new script.
    the problem is i don't have any knowledge of regex at all so i am not able to convert the code of smiley into an image.

    heres what i tried:

    
    $string="Smile: [smiley]";
    preg_replace("/\[(.*?)\]/","<img src='images/$1.gif'>",$string);
    
    PHP:

    plz help me this is first time i am using preg_replace
     
    arpit13, Dec 2, 2011 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    That should work. What's not working for you? That would output: Smile: <img src='images/smiley.gif'>
     
    jestep, Dec 2, 2011 IP
  3. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #3
    Maybe he's stuck with how to output it?
    
    <?php
    
     $string="Smile: [smiley]";
    
    $replacement = preg_replace('#\[(.*?)\]#','<img src=\'images/$1.gif\'>',$string);
    
    echo $replacement;
    
    ?>
    
    PHP:
     
    MyVodaFone, Dec 2, 2011 IP
    arpit13 likes this.
  4. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #4
    oops silly error on my side :(
    i interpreted the example on php.net wrongly.
    anyways its working now thx
     
    arpit13, Dec 3, 2011 IP