removing strange characters from php string

前端 未结 14 954
忘了有多久
忘了有多久 2021-01-31 17:45

this is what i have right now

Drawing an RSS feed into the php, the raw xml from the rss feed reads:

Paul’s Confidence

The ph

14条回答
  •  感情败类
    2021-01-31 18:28

    This is my function that always works, regardless of encoding:

    function RemoveBS($Str) {  
      $StrArr = str_split($Str); $NewStr = '';
      foreach ($StrArr as $Char) {    
        $CharNo = ord($Char);
        if ($CharNo == 163) { $NewStr .= $Char; continue; } // keep £ 
        if ($CharNo > 31 && $CharNo < 127) {
          $NewStr .= $Char;    
        }
      }  
      return $NewStr;
    }
    

    How it works:

    echo RemoveBS('Hello õhowå åare youÆ?'); // Hello how are you?
    

提交回复
热议问题