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? Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/ 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", Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625882 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. Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625890 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", Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625892 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(). Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625914 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 Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625933 Share on other sites More sharing options...
DarkWater Posted August 26, 2008 Share Posted August 26, 2008 Lol, hey Phil. I'm on MSN. Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625935 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? Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625937 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 Link to comment https://forums.phpfreaks.com/topic/121390-solved-array-wildcard/#findComment-625940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.