tox_yray Posted August 28, 2006 Share Posted August 28, 2006 Ok, here is the problem:I have this little bit of code:[code]<?php$lole = array('rouge', 'vert', 'bleu');$STRING = "Le ciel est $$!!WIDTH2++--";echo preg_replace("/\\$\\$!!WIDTH(\\d+)\\+\\+--/", "\\1", $STRING);?>[/code]The Regex is proper as the script echoes "Le ciel est 2". However, I would like him to echo "Le ciel est bleu" (where "bleu" is the index 2 of array $lole... You get the picture...)I tried many different solutions but none seem to work. Here is what I've tried:[code]echo preg_replace("/\\$\\$!!WIDTH(\\d+)\\+\\+--/", $lole["\\1"], $STRING);echo preg_replace("/\\$\\$!!WIDTH(\\d+)\\+\\+--/", "$lole[\\1]", $STRING);echo preg_replace("/\\$\\$!!WIDTH(\\d+)\\+\\+--/", $lole[\\1], $STRING);[/code]Thanks for any help you can provide,Bruno M-A. Quote Link to comment Share on other sites More sharing options...
effigy Posted August 28, 2006 Share Posted August 28, 2006 [code]echo preg_replace('/\$\$!!WIDTH(\d+)\+\+--/e', "\$lole[$1]", $STRING);[/code] Quote Link to comment Share on other sites More sharing options...
tox_yray Posted August 29, 2006 Author Share Posted August 29, 2006 Works like a charm!!! Thanks a bunch! Quote Link to comment Share on other sites More sharing options...
GameMusic Posted September 3, 2006 Share Posted September 3, 2006 Try preg_replace_callback too. 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.