How to get rid of these illegal characters ?

Discussion in 'PHP' started by abhi_cyco, Sep 13, 2011.

  1. #1
     Apple  Bat  Cat  Rat  Mat  Fat

    I want to get rid of these illegal characters. Can you suggest some solution. I am using php as programming language.

    These appears when i paste something from MS word to textarea of html page.

    I tried the below methods which didnt worked out

    1) $contents = preg_replace('/[^\r\n\t\x20-\x7E\xA0-\xFF]/', ' ', $contents);

    2) $string = preg_replace('/[^(\x20-\x7F)]*/','', $string);

    3) (WORST OPTION)$retrievedAreaText = $_POST["textAreaId"];
    $illegalChars = array("",); //others
    $retrievedAreaText = str_replace($illegalChars,"",$retrievedAreaText);

    Please Help.
     
    abhi_cyco, Sep 13, 2011 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,899
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #2
    MS Word is a pain - literally which is why people use text editors such as tinymce and ckeditor, The and effort involved in writing something to effectively parse a word document just isn't worth it.
     
    sarahk, Sep 14, 2011 IP
  3. zeronese

    zeronese Peon

    Messages:
    83
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    in your html, if you have not yet done so, try changing your charset to utf-8 and see if that solves the problem.
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     
    zeronese, Sep 20, 2011 IP