Solved

regular expression to remove control characters but keep newline

Posted on 2006-11-16
1
1,153 Views
Last Modified: 2013-12-12
Hi All,

I have the following regex to remove control characters, but in some case i want to keep the newline character.

$input = preg_replace('!\p{C}!u', '', $input);

Does anyone know how to modify this  to allow for the newlines in the string?

Thanks for the help!

0
Comment
Question by:amagondes
1 Comment
 
LVL 49

Accepted Solution

by:
Roonaan earned 250 total points
ID: 17971760
I think there is no such way using the unicode replacement. An alternative might be to first split a string on \n then preg_replace it parts and then reconstruct the string.

Also, to quote the manual:
Matching characters by Unicode property is not fast, because PCRE has to search a structure that contains data for over fifteen thousand characters. That is why the traditional escape sequences such as \d and \w do not use Unicode properties in PCRE.

-r-
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question