iceblox Posted August 26, 2008 Share Posted August 26, 2008 Hi All, I have a replacement script which uses this line to replace data that it matches within a csv file. "£95.00 upfront cash back." => "0", Is there anyway of changing 95.00 for a wild card? so that i dont have to add every monerty value in? Quote Link to comment Share on other sites More sharing options...
Mchl Posted August 26, 2008 Share Posted August 26, 2008 A wild guess: $moneyValue." upfront cash back." => "0", Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 26, 2008 Share Posted August 26, 2008 Yes, with regular expressions and preg_replace(): <?php //$file contains file contents as a string $find = array( '~£[0-9]{1,2}\.[0-9]{2} upfront cash back\.~' ); $replace = array( '0' ); $file = preg_replace($find, $replace, $file); ?> Instead of searching for 95.00 it searches for 1-2 digits, a dot, and then 2 digits. To search for e.g. 1-3 digits before the dot, use {1,3} instead of {1,2} in the code. Quote Link to comment Share on other sites More sharing options...
iceblox Posted August 26, 2008 Author Share Posted August 26, 2008 Thanks for the help. I have the rest of the script working in terms of replacements. So would this code work? Based on your example..? "~£[0-9]{1,2}\.[0-9]{2} upfront cash back\.~" => "0", Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 26, 2008 Share Posted August 26, 2008 Show me your code, and I'll tell you how to integrate it. My code only works when run through preg_replace(), and my guess is you're using str_replace(). Quote Link to comment Share on other sites More sharing options...
iceblox Posted August 26, 2008 Author Share Posted August 26, 2008 my code is quite long.. but your right it is str_replace Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Lol, hey Phil. I'm on MSN. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted August 26, 2008 Share Posted August 26, 2008 Lol, hey Phil. I'm on MSN. Trying to steal my client? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Lol, hey Phil. I'm on MSN. Trying to steal my client? I wrote the script for him... o_O 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.