开发者

Remove HTML special charcters

开发者 https://www.devze.com 2023-01-22 00:42 出处:网络
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 th

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

精彩评论

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