Unable to Store Arabic in MYSQL database using PHP

前端 未结 3 1617
一整个雨季
一整个雨季 2021-01-19 11:28

I have been trying to find a solution for past few hours but unable to do so. I have tried each and every possible solution on the Internet and this forum but nothing seems

3条回答
  •  天涯浪人
    2021-01-19 12:24

    It looks like all the code on the server side is working properly. The error seems to be happening when the browser submits the form back the server and then either the data is wrong or is mis-interpreted.

    1) Please can you confirm that you have the Multi-Byte extension installed. If you don't then PHP will probably be failing to interpret the characters from the browser correctly. http://php.net/manual/en/book.mbstring.php

    2) Can you double-check that the page is actually picked up as UTF8 by the browser. It is possible that the browser isn't sure what character set the page is in, but is still displaying the Arabic characters correctly because it's guessing how to display them. So first.

    In your HTML, add this meta tag:

    Also add this PHP header at top of the script:

    header("Content-Type: text/html;charset=UTF-8");

    3) If those don't work please can you look at the actual form submission in the browser, either using the developer tools in Chrome or Firebug in Firefox to see exactly what is being submitted.

    e.g. I just did a test page to submit some Arabic text to a test page on my server. In the request I can see the form is encoded as

    Content-Length: 61
    test=%26%231607%3B%26%231594%3B%26%231594%3B%26%231601%3B&go=
    

    Splitting the text into individual characters I can see

    %26
    %231607
    %3B
    %26
    %231594
    %3B
    %26
    %231594
    %3B%26
    %231601
    %3B
    

    i.e. the Arabic characters are being encoded correctly for me - perhaps you would see something different.

提交回复
热议问题