PHP text formating: Detectng several symbols in a row
- by ilnur777
I have a kind of strange thing that I really nead for my text formating. Don't ask me please why I did this strange thing! ;-)
So, my PHP script replaces all line foldings "\n" with one of the speacial symbol like "|". When I insert text data to database, the PHP script replaces all line foldings with the symbol "|" and when the script reads text data from the database, it replaces all special symbols "|" with line folding "\n".
I want to restrict text format in the way that it will cut line foldings if there are more than 2 line foldings used in each separating texts.
Here is the example of the text I want the script to format:
this is text... this is text... this is text...this is text...this is text... this is text... this is text... this is text... this is text... this is text...
this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text...
I want to restict format like:
this is text... this is text... this is text...this is text...this is text... this is text... this is text... this is text... this is text... this is text...
this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text... this is text...
So, at the first example there is only one line folding between 2 texts and on the second example there are 3 line foldings between 2 texts.
How it can be possible to replace more than 2 line foldings symbols "|" if they are detected on the text?
This is a kind of example I want the script to do:
$text = str_replace("|||", "||", $text);
$text = str_replace("||||", "||", $text);
$text = str_replace("|||||", "||", $text);
$text = str_replace("||||||", "||", $text);
$text = str_replace("|||||||", "||", $text);
...
$text = str_replace("||||||||||", "||", $text);
$text = str_replace("|", "<br>", $text);