[英]Remove particular UTF-8 character from string with PHP
I get some strings from remote API and someone contains char ð
(I couldn't get rid of or replace it) 我从远程API获得了一些字符串,并且有人包含
ð
(我无法摆脱或替换它)
I tried 我试过了
$str = str_replace("ð", "", $str);
$str = strtr($str,'ð','');
There is no effect 没有效果
$str = iconv( "UTF-8", "ISO-8859-1//TRANSLIT", $str);
or
$str = iconv( "UTF-8", "ISO-8859-1//TRANSLIT//IGNORE", $str);
hope this will work. 希望这会起作用。 use iconv() instead of str_replace
使用iconv()代替str_replace
尝试替换其html实体,例如:
str_replace("ð","",$str);
Your php file is not encoded in UTF-8 according to me. 根据我的说法,您的php文件未使用UTF-8编码。 Specify it using the headers.
使用标题指定它。 Use the code below
使用下面的代码
<?php
header('Content-Type: text/html; charset=utf-8');
$str="hð";
$str = strtr($str,'ð','');
echo $str; // print h
or 要么
<?php
header('Content-Type: text/html; charset=utf-8');
$str="hð";
$str = str_replace("ð", "", $str);
echo $str; // prints h
Hope this helps you 希望这对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.