removing strange characters from php string

前端 未结 14 923
忘了有多久
忘了有多久 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:13

    Use the below PHP code to remove

    html_entity_decode(mb_convert_encoding(stripslashes($name), "HTML-ENTITIES", 'UTF-8'))
    
    0 讨论(0)
  • 2021-01-31 18:14

    It does not work You need to use $arr1 = str_split($str) then foreach and echo($arr1[$k]) This will show you exactly which characters are written into the string.

    0 讨论(0)
  • 2021-01-31 18:15

    1.The order of the strings in the $find array is significant. 2.This string "‘" should contain a tilde and look like three characters. If I save the .php file with my Genie editor it gits changed to just two characters "â€". 3.This is a useful reference https://www.i18nqa.com/debug/utf8-debug.html

    <?php
    $text = "‘’“â€1‘ 2’ 3â€â€œâ€™â€˜ 4’ 5 6 7’ ‘, ’, “, â€â€˜";
    echo($text . "<br>");
    $find = array("‘", "’", "“", "â€");
    $replace = array("‘", "’", "“", "”");
    $text = str_replace($find, $replace, $text);
    echo($text);
    ?>
    
    0 讨论(0)
  • 2021-01-31 18:18

    Try this:

    $newtitle = html_entity_decode($newtitle, ENT_QUOTES, "UTF-8")
    

    If this is not the solution browse this page http://us2.php.net/manual/en/function.html-entity-decode.php

    0 讨论(0)
  • 2021-01-31 18:21
    Please Try this. 
    
    
    $find[] = '/&acirc;&#128;&#156;/' //'“'; // left side double smart quote
    $find[] = '/&acirc;&#128;&#157;/' //'â€'; // right side double smart quote
    $find[] = '/&acirc;&#128;&#152;/' //'‘'; // left side single smart quote
    $find[] = '/&acirc;&#128;&#153;/' //'’'; // right side single smart quote
    $find[] = '/&acirc;&#128;&#133/'  //'…'; // elipsis
    $find[] = '/&acirc;&#128;&#150;/' //'—'; // em dash
    $find[] = '/&acirc;&#128;&#147;/' //'–'; // en dash
    
    $replace[] = '&ldquo;' // '"';
    $replace[] = '&rdquo;' // '"';
    $replace[] = '&lsquo;' // "'";
    $replace[] = '&rsquo;' // "'";
    $replace[] = '&#8943;' // "...";
    $replace[] = '&mdash;' // "-";
    $replace[] = '&ndash;' // "-";
    
    $text = str_replace($find, $replace, $text);
    
    0 讨论(0)
  • 2021-01-31 18:27

    I solved the problem. Seems to be a short fix rather than the larger issue, but it works.

    $newtitle = str_replace('’', "'", $newtitle);
    

    I also found this useful snippit that may help others with same problem;

    <?
    $find[] = '“'; // left side double smart quote
    $find[] = 'â€'; // right side double smart quote
    $find[] = '‘'; // left side single smart quote
    $find[] = '’'; // right side single smart quote
    $find[] = '…'; // elipsis
    $find[] = '—'; // em dash
    $find[] = '–'; // en dash
    
    $replace[] = '"';
    $replace[] = '"';
    $replace[] = "'";
    $replace[] = "'";
    $replace[] = "...";
    $replace[] = "-";
    $replace[] = "-";
    
    $text = str_replace($find, $replace, $text);
    ?>
    

    Thanks everyone for your time and consideration.

    0 讨论(0)
提交回复
热议问题