Blocking Special Characters Created with (alt + n) (PHP)

To give an example.. One day you will come across a space character created with alt + 255 passing through the trim in the space control. That's why the checks you make will not work and malicious people will send empty content. To prevent this, we need to filter such special characters with the help of a function.

function altReplace($string){
	$search = array(
		chr(0xC2) . chr(0xA0), // c2a0; Alt+255; Alt+0160; Alt+511; Alt+99999999;
		chr(0xC2) . chr(0x90), // c290; Alt+0144
		chr(0xC2) . chr(0x9D), // cd9d; Alt+0157
		chr(0xC2) . chr(0x81), // c281; Alt+0129
		chr(0xC2) . chr(0x8D), // c28d; Alt+0141
		chr(0xC2) . chr(0x8F), // c28f; Alt+0143
		chr(0xC2) . chr(0xAD), // cdad; Alt+0173
	$string = str_replace($search, '', $string);
	return trim($string);

Yes, now if we use the post or get values as follows;


We would not encounter such problems.


There are no comments, make the firs comment