ryancooper Posted April 11, 2011 Share Posted April 11, 2011 if (stripos($data, 'numbers') !== false) { $data = preg_replace('/\d/', '', $data); } This is the code i was able to come up with some help from the people at sof... It's supposed to remove the numbers mixed in characters in between quotations if a keyword is found. In the example above that word is numbers, however this example removes all numbers from the entire string and if i change the regex to '/"\d+"/' to only remove numbers matched within quotes it no longer works. This may or may not need to be moved, i realize the regex maybe the problem, however i wasnt sure if the quotation section needed to be defined as a new object to have the preg_replace applied to and the reinserted back in place, thus leaving the numbers not in quotations alone. A example would be: I am 13 as of today, what an unlucky number. "B1D3AY" Would be I am 13 as of today, what an unlucky number. "BDAY" Stripping the 1 and 3 from BDAY but leaving the 13 not inside quotations. Quote Link to comment Share on other sites More sharing options...
sasa Posted April 14, 2011 Share Posted April 14, 2011 try <?php $test = 'I am 13 as of today, what an unlucky number. "B1D3AY"'; function remove_numbers($a){ return preg_replace('/\d/','', $a[0]); } echo preg_replace_callback('/"[^"]+"/','remove_numbers',$test); ?> 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.