开发者

Remove HTML special charcters

How do i remove , , ° like special characters from a strin开发者_JAVA百科g in PHP

Actually i need to read the contents from a text file and need to remove the html special characters except the alphabets and digits from it


Or, if you want to use a RegEx, use:

$str = 'a“bc”def°g';
$str = preg_replace("[^A-Za-z0-9 ]", "", $str);


One way would be (eg)

$str = 'a“bc”def°g';
$special = array('“','”','°');
$str = str_replace($special,'',$str);


Per the edit- to read the file contents, remove everything except alphanumerics and space characters then write the result to the same file, you can use:

$file= "yourfile.txt";
$file_content = file_get_contents($file);
$fh = fopen($file, 'w');
$file_content=preg_replace("[^A-Za-z0-9 ]", "", $file_content);
fwrite($fh, $file_content);
fclose($fh);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜