Arabic PDF Form to PHP to MYSQL, Unicode Decoding?

2019-09-11 05:32发布

问题:

I am using Acrobat professional to create a PDF Form, the form is filled with arabic, and I created a PHP file to get the form fields and insert it into a mysql database, I tried decoding the arabic text ãÍãÏ with utf_encode() and utf_decode() the word is محمد and the database is utf8_bin. and solutions?

<?php
error_reporting(E_ALL & ~E_NOTICE);
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "dbTest";

if (isset($_POST['txtName'])) {$txtName= $_POST['txtName'];};

$link = mysqli_connect($servername, $username, $password, $dbname) or     die("UNable to connect");
$qq1 = "set character_set_server='utf8'";
$qq2 = "set names 'utf8'";

//mysqli_query($link, $qq1) or die(mysqli_error($link));
//mysqli_query($link, $qq2) or die(mysqli_error($link));
//$txtName = iconv("UTF-8//TRANSLIT//IGNORE", "Windows-1252//TRANSLIT//IGNORE", $txtName);
//$txtName = iconv("Windows-1256//TRANSLIT//IGNORE", "UTF-8//TRANSLIT//IGNORE", $txtName);

$query = "INSERT INTO  tblTest Values('$txtName')";

mysqli_query($link, $query) or die(mysqli_error($link));

?> and here is the database

CREATE TABLE IF NOT EXISTS `tbltest` (`txtName` varchar(244) COLLATE tf8_bin DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;


INSERT INTO `tbltest` (`txtName`) VALUES
('ãÍãÏ Úæäí ãÍãæÏ');

回答1:

It's still not clear how you submit the data but the answer is available in the mentioned simliar question.

The charset for a standard submit action is not specified/adjustable by the PDF specification until PDF 2.0 and the reader application may choose any appropriate charset.

Use a JavaScript action to submit the form data with a specific charset instead of a submit action:

submitForm({
    cURL: "https://www.example.com/your-script.php",
    cSubmitAs: "HTML",
    cCharset: 'utf-8'
});