dpbfb7119 2017-01-14 14:02
浏览 40
已采纳

PHP preg_match不允许æøå

I am trying to make my registration script accept only letters and æøå, but nothing I've tried so far has worked. It still won't accept æøå.

This is my code so far

if ($_POST['first'] != "" && preg_match("%^[-a-zA-Z æøå\/]+$%", $_POST['first']) == true && strlen($_POST['first']) > 0) { 
    $input_first = mysqli_real_escape_string($con,$_POST['first']); } 
else { header("Location: ../register.php?n=2"); exit; die(); }

What am I doing wrong?

  • 写回答

1条回答 默认 最新

  • dongmale0656 2017-01-14 14:41
    关注

    If your PHP file is already UTF-8 encoded, you should tell your database, that you need UTF-8. Instead of fiddling with the configurations of MySQL, just tell your connection object, which character-set you expect, the database does the rest for you.

    This is an example for a mysqli connection object:

     //Test-ak
      $db = new mysqli($dbHost, $dbUser, $dbPw, $dbName);
      $db->set_charset("utf8");
    

    Afterwards your queries will return UTF-8 encoded results.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部