I have a regular expression which allows only certain characters in the message.
What I’m trying to achieve is to allow line breaks as well which will be preserved using nl2br function.
That’s what I have so far:
preg_replace('/[^a-zA-Z0-9ńśćółęążź\ .,-]/','',$message)
As far as I have checked, the following expression should preserve line breaks but I’m having problems adding it to the above expression:
/(\r|\n|\r\n){2,}/
You would just want to add
\r&\nto the list of characters to not replace. So:In the above expression I’ve also had to change the
'to ” (so that\r&\nare recognised) but have also had to escape the.and-characters