I've been trying to solve this one using regular expressions (preg_replace) but can't find the solution. Thought I'd ask for the good people's advice. B-)
I have a string which has a few [tags] in it. I want to replace everything between the start [tag] and the end [/tag] with some character (same one), but it's important I maintain the number of characters in between the tags.
Example:
[tt]this is [tag]a sample[/tag] of text for [tag]masking[/tag] just parts [tag]of it[/tag], see?[/tt]
will be changed into:
[tt]this is [tag]########[/tag] of text for [tag]#######[/tag] just parts [tag]#####[/tag], see?[/tt]
The string may have no tags at all, in which case nothing should change.
For matters of simplicity, there is only one type of tag (e.g. [tag]text[/tag]). In the real case there are 4-5, but all known in advance (constants).
The same tag may appear more than once in the string.
I was thinking of something like
[tt]$str = preg_replace("/\[tag\]?[\w|\s]*\[\/tag\]?/i",
"[tag]#[/tag]",
$str);[/tt]
But it doesn't "count" the number of character, meaning it gives me the following result:
[tt]this is [tag]#[/tag] of text for [tag]#[/tag] just parts [tag]#[/tag], see?[/tt]
Help me. Plllllllllease![[hourglass] [hourglass] [hourglass]](/data/assets/smilies/hourglass.gif)
Thanks!!!![[peace] [peace] [peace]](/data/assets/smilies/peace.gif)
Karnaf
I have a string which has a few [tags] in it. I want to replace everything between the start [tag] and the end [/tag] with some character (same one), but it's important I maintain the number of characters in between the tags.
Example:
[tt]this is [tag]a sample[/tag] of text for [tag]masking[/tag] just parts [tag]of it[/tag], see?[/tt]
will be changed into:
[tt]this is [tag]########[/tag] of text for [tag]#######[/tag] just parts [tag]#####[/tag], see?[/tt]
The string may have no tags at all, in which case nothing should change.
For matters of simplicity, there is only one type of tag (e.g. [tag]text[/tag]). In the real case there are 4-5, but all known in advance (constants).
The same tag may appear more than once in the string.
I was thinking of something like
[tt]$str = preg_replace("/\[tag\]?[\w|\s]*\[\/tag\]?/i",
"[tag]#[/tag]",
$str);[/tt]
But it doesn't "count" the number of character, meaning it gives me the following result:
[tt]this is [tag]#[/tag] of text for [tag]#[/tag] just parts [tag]#[/tag], see?[/tt]
Help me. Plllllllllease
![[hourglass] [hourglass] [hourglass]](/data/assets/smilies/hourglass.gif)
Thanks!!!
![[peace] [peace] [peace]](/data/assets/smilies/peace.gif)
Karnaf