Jump to content

Only use preg_replace in between quotations...


ryancooper

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.