removing strange characters from php string

前端 未结 14 1061
忘了有多久
忘了有多久 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 will remove all non-ascii characters / special characters from a string.

    //Remove from a single line string
    $output = "Likening ‘not-critical’ with";
    $output = preg_replace('/[^(\x20-\x7F)]*/','', $output);
    echo $output;
     
    //Remove from a multi-line string
    $output = "Likening ‘not-critical’ with \n Likening ‘not-critical’ with \r Likening ‘not-critical’ with. ' ! -.";
    $output = preg_replace('/[^(\x20-\x7F)\x0A\x0D]*/','', $output);
    echo $output;

提交回复
热议问题