开发者

How to get rid of these illegal characters ?

 Apple  Bat  Cat  Rat  Mat  Fat

I want to get rid of these illegal characters.开发者_JS百科 Can you suggest some solution. I am using php as programming language.

These appears when i paste something from MS word to textarea of html page.


If you just want to extract the ASCII, then you could try this:

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


PHP has String replace. I assume that you're trying to process submitted form data, and want to sanitize the textarea value to remove these characters.

$retrievedAreaText = $_POST["textAreaId"];
$illegalChars = array("",); //others
$retrievedAreaText = str_replace($illegalChars,"",$retrievedAreaText);
//further processing


Give a try to this one:

$string = htmlentities($string, ENT_COMPAT, "UTF-8");

It converts special characters to utf standards or in any standard that yo want. It is real that special chars mostly are trouble.

Hope this helps you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜