htmlentities destroys utf-8 strings

前端 未结 5 559
旧巷少年郎
旧巷少年郎 2020-12-15 17:21

I got something weird happening here and I can\'t understand why, on my php 5.2.5 server (Just on Linux ,Windows php servers doesn\'t have same problem) When I use a POST F

5条回答
  •  感情败类
    2020-12-15 17:45

    And if you don't want to worry about so many different charset codings or if htmlentities doesn't work for you, here the alternative: I used mysqli DB connection (and PHPV5) Form post for writing/inserting to MySQl DB.

    $Notes = $_POST['Notes']; //can be text input or textarea.
    
    $charset = mysqli_character_set_name($link);  //mysqli connection
    printf ("To check your character set but not necessary %s\n",$charset);  
    
    $Notes = str_replace('"', '"', $Notes);  //double quotes for mailto: emails.  
    $von = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");  //to correct double whitepaces as well
    $zu  = array("ä","ö","ü","ß","Ä","Ö","Ü"," ","é");  
    $Notes = str_replace($von, $zu, $Notes);  
    echo " Notes:".$Notes."
    " ; $Notes = mysqli_real_escape_string($link, $Notes); //for mysqli DB connection. // Escapes special characters in a string for use in an SQL statement echo " Notes:".$Notes ; //ready for inserting

提交回复
热议问题