Only allow English characters/letters/numbers and a few special characters

<>

This question already has an answer here:

Answers


You may create an array of allowed characters and then filter those that are not allowed:

$allowed = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), array(' ', '+', '/', '-', '*', '.')); // Create an array of allowed characters

$string = 'This is allowed and this not é Ó ½ and nothing 123.'; // test string

$array = str_split($string); // split the string (character length = 1)

echo implode('', array_intersect($array, $allowed)); // Filter and implode !

Online demo.


Need Your Help

Strange AV while loading an icon from the resource stream

delphi resources icons delphi-xe2

I'm adding icons to my project via Resources and Images dialog, and decided to walk away from TIcon.LoadFromResourceName because it does not perform any error checking. I wrote seemingly equivalent...

CMake visual studio debug/release config

c++ visual-studio configuration cmake

I'm setting up my visual studio project to use CMake, but I got two issues I haven't been able to solve yet.

Android LogCat continuously repeating a warning: “Addition of standard header … not allowed”

android debugging sync htc flickrj

I've been developing an Android application using version 2.3.3 (API 10). The application simply uses Flickr Java API (flickrj) to make certain search queries based on tags, date, geographical info...