php - Removing redundant line breaks with regular expressions -
I am developing in PHP which only displays messages that are posted by visitors (the ideal website's Around the subject). Anyone can post three messages for one hour.
Since the website will be only one page, I would like to control the vertical length of each message. However, I want to preserve at least partially the line breaks in the original message. A compromise would be to allow two line breaks, but if more than two, replace them with a total of two line breaks in a row. Stack overflow executes this.
For example:
"porcupines \ nare \ n \ n \ n \ nporcupiney."
will be changed to
>A difficult aspect to test line breaks is that they are likely to be collected and stored \ r. \ N, \ r, or \ n
My question: Using regular expressions in PHP (with functions like preg_match () and preg_replace ()), I have more than two line breaks in one line How can I check for examples (between or without spaces) and then change them for two line breaks?
preg_replace ('/ (?: (?: \ R \ n | \ r | \ N) \ s *) {2} / s ',' \ n \ n ", $ text)
Comments
Post a Comment