Kasuke_Akira Posted March 19, 2007 Share Posted March 19, 2007 Here's my code: function cmc_convert ($str) { $simple_search = array( '16', '12', '11', '10', '9', '8', '7', '6', '5', '4', '3', '2', '1', 'W', 'U', 'B', 'R', 'G' ); $simple_replace = array( '<img src=images/cmc_16.png>', '<img src=images/cmc_12.png>', '<img src=images/cmc_11.png>', '<img src=images/cmc_10.png>', '<img src=images/cmc_9.png>', '<img src=images/cmc_8.png>', '<img src=images/cmc_7.png>', '<img src=images/cmc_6.png>', '<img src=images/cmc_5.png>', '<img src=images/cmc_4.png>', '<img src=images/cmc_3.png>', '<img src=images/cmc_2.png>', '<img src=images/cmc_1.png>', '<img src=images/cmc_white.png>', '<img src=images/cmc_blue.png>', '<img src=images/cmc_black.png>', '<img src=images/cmc_red.png>', '<img src=images/cmc_green.png>' ); $str = preg_replace($simple_search, $simple_replace, $str); return $str; } Basically....I don't know why it isn't working. I realize it's probably in the $simple_search array, but I am not too good at string manipulation and was curious what I'm doing wrong. If you know what I'm doing wrong and how to fix it, if you do fix it, can you explain to me why? So I understand what's going on. Thanks. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 19, 2007 Share Posted March 19, 2007 preg patterns need a starting and ending delimiter. Look at the following example from the manual: $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = '/fox/'; $replacements[2] = 'bear'; $replacements[1] = 'black'; $replacements[0] = 'slow'; echo preg_replace($patterns, $replacements, $string); In this case, the delimiter is "/", and appears at the start and end of every search pattern. Quote Link to comment Share on other sites More sharing options...
Kasuke_Akira Posted March 19, 2007 Author Share Posted March 19, 2007 I tried that and it didn't work. Quote Link to comment Share on other sites More sharing options...
btherl Posted March 19, 2007 Share Posted March 19, 2007 Can you post the code you tried? If you need to convince yourself that it works, try the sample code I posted. Quote Link to comment Share on other sites More sharing options...
Kasuke_Akira Posted March 19, 2007 Author Share Posted March 19, 2007 OK, well I switched it from using my arrays, to setting it up like your example instead. So that will do for now. Thanks. I'll just fiddle with my own code later....mebbe i can figure out wut I'm doing wrong. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.