php - Censor words with the same number of stars than the word length -


I want to change all the words of 1 or 2 characters by stars. I currently use this rule: / P>

  $ validTxt = preg_replace ("/ \\ b \\ w {1,2} \\ b /", '*', $ validTxt);   

But when words are 2 letters, then it is replaced with only 1 star, not 2. I want a fast way to do this, display is a priority, even if it needs 100 lines.

To remove the correct time, 'e' modifiers which you can use in the replacement string Allows executable code to be kept. (Note that this 'e' modifier can only be used with preg_replace () ). This is the tested task step:

Comments