I'm fairly new to regular expressions in general and one of my learning projects is to create a filter that will substitute select words, or combination of characters, with the appropriate number of *'s - corresponding to the number of characters that match the substring to be replaced.
For example, let's say I add the word 'blah' to the filter. I would like it to be replaced with '****', and 'myveryownwordwithnospaces' with '************************'.
I'm quite comfortable now with pattern syntax and all, but I'm at a loss for trying to figure out how to add 'dynamically substituted substring' code.
Consider the following example:
$modstring = preg_replace("#$invalid#i", '*moderated*', $mainstring);
That is what I would call a static substitution. No matter how long the "$invalid" word, it will always be replaced with *moderated*. I have tried for days to figure out how I might substitute each character in a matched substring with a * (thereby effectively adding the appropriate number of *'s for a matched substring of a given length).
Thanks in advance for any help you can provide
Geneith
For example, let's say I add the word 'blah' to the filter. I would like it to be replaced with '****', and 'myveryownwordwithnospaces' with '************************'.
I'm quite comfortable now with pattern syntax and all, but I'm at a loss for trying to figure out how to add 'dynamically substituted substring' code.
Consider the following example:
$modstring = preg_replace("#$invalid#i", '*moderated*', $mainstring);
That is what I would call a static substitution. No matter how long the "$invalid" word, it will always be replaced with *moderated*. I have tried for days to figure out how I might substitute each character in a matched substring with a * (thereby effectively adding the appropriate number of *'s for a matched substring of a given length).
Thanks in advance for any help you can provide
Geneith