detect and strip out any foreign text, while keeping special characters

I am trying to filter out all non latin characters, such as γειά σου with javascript / regex, while allowing special characters such as !@#$%^&*(). But if JS is not possible then php with preg_replace perhaps. Ive tried JS str = str.replace(/[^a-z0-9\-.,:;]/i, ""); but that didnt do anything. With php $str = preg_replace('[^a-zA-Z0-9\xC0-\xFF]', '', $str); but got the same results.

This echo htmlentities($str, ENT_QUOTES, "ISO-8859-1"); however gave me garbled text, maybe i can somehow detect that?

Q: what is the best way to do this?

Answers


this seems to be working when i tested it, but you will want to double check:

$output = preg_replace('/[^(\x20-\x7F)]*/','', $output);

Need Your Help

Two's Complement — How are negative numbers handled?

math twos-complement

It is my understanding that numbers are negated using the two's compliment, which to my understanding is: !num + 1.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.