I’m sure the answer is “No”, but is there some way when using preg_replace to get some sort of list of what was replaced?
I have created a “bad word” checker, and was hoping to get a tally of any bad words found.
For example, it would be useful to know that in a user’s comments they said “Damn” once, “Crap” twice, and “F***” four times!!
Looking in the Manual, it appears the function will return a total count, but what would be much more useful is to get an array containing all offending words so I can then do analysis on the replacement!
Is there any reasonable way I could accomplish this?
Originally I just wanted to feed my function some block of text (e.g. User Comment) and have it replace any bad words with ****.
So I used preg_replace.
That makes sense, right?
Well, after I got that working last night, I decided it might be useful to do some analysis on the violator and keep some sort of tally on their cussing ways!
So as a new requirement, I wanted to get a list of all bad words from the submitted text. (However, the process above remains unchanged.)
I apologize if what you are suggesting is obvious to you, but I don’t see how using preg_match_all will help my main goal of replacing bad words in a block of text. (To me it sounds like it would just create an array that would be disconnected from the text.)
So I can keep my current code which has the $patterns as an array, the $replacement as a string, and the $source as a string, and then use preg_match_all as a completely separate process?