I'm trying to figure out how to get Hebrew characters. In my connection.php I have $con->set_charset('utf8');, so letters appears in input fields and recorded properly in MySql database with this connection.php:
<?php
header("Access-Control-Allow-Origin: *");
header('Content-type: text/xhtml; charset=windows-1255');
$con = new mysqli('localhost:XXXX', 'user', 'password');
$con->set_charset('utf8');
if (!$con)
{
echo 'Not Connected To Server';
}
if (!mysqli_select_db ($con, 'mydb'))
{
echo 'Database Not Selected';
}
?>
But in several places, seems like, when I'm trying to get it from list, for example below home.ts this.function(); http request, it appears this way:
function() {
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({ headers: headers });
let postParams = '&user=' + this.user;
this.http.post(this.phpPath + "select.php", (postParams), options)
.subscribe(data => {
var nmb = (data.text().split(".").length);
let x = data.text().split(".");
for (var i = 0; i < nmb; i++) {
var c = x[i];
this.list.push({ id: i, name: this.s + c }, );
}
}, error => {
console.log(error);
});
}
particularselect.php uses connection.php:
<?php
require 'connection.php';
$user = mysqli_real_escape_string($con, $_POST["user"]);
$sql = "SELECT name FROM tab where user='".$user."'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo $row["name"].'.';
}
} else {
echo "0 results";
}
mysqli_close($con);
?>
I've tried to add <meta charset="UTF-8"> to home.html, but index.html already contains it. And also I've tried to save home.html with notepad encoded with UTF-8, but nothing helps.
header(‘Content-type: text/xhtml; charset=windows-1255’); already in connection.php, and in result I have Hebrew characters in MySql database record from other http requests and .php back-end.
For example input in application:
or in MySql table:
But this does not affect button, as well as several other places in same application UI with same connection.php, like this one from particular code:
if there is no header(‘Content-type: text/xhtml; charset=windows-1255’); it looks this way:
or in application:
but it is different from:
I’m not quite understand, what I'm doing wrong and have to change with XHTML, sending UTF-8 and promising windows-1255, but I’ve tried return it differently, as a json from select.php with array $myArray[] = $row; as let obj: MyObj = JSON.parse(data.text()); in http request.
In result console:
\u05d0\u05d1\u05d2\u05d3
And object is undefined
I found this stackoverflow answer, which says that Old-Style ASCII Property Lists allows only ASCII characters, and I have print description of a string. Maybe it is a reason, but I’m not sure, how to do it in Ionic2 TypeScript
EDIT 1:
I've edited connection.php with $con->set_charset('utf8mb4'); instead of utf8, and also I've used $con->query("SET collation_connection = utf8mb4_unicode_520_ci");:
$con = new mysqli('host', 'user', 'password');
$con->set_charset('utf8mb4');
$con->query("SET collation_connection = utf8mb4_unicode_520_ci");
MySql database row on server is utf8_general_mysql500_ci, which contains hebrew characters record and retrieves by request in other places of application.
I'm not sure, how to set <meta charset=UTF-8> for Ionic2 html page, it is already in <head> of project index.html. With adding to home.html or any other page <ion-header>, nothing changes.
in case of \u05d0\u05d1\u05d2\u05d3 now with echo json_encode($myArray, JSON_UNESCAPED_UNICODE); seems like returns proper string with English json names, but hebrew still in Mojibake. Anyway, to avoid Unicode codepoints, in my case it is enough to get echo as $row["name"].'.'; without array and object in http request. But I'm not sure, what to do with Mojibake
EDIT 2:
Show create table, name column contains hebrew:
CREATE TABLE `band` (
`ID` int(20) NOT NULL AUTO_INCREMENT,
`name` varchar(300) COLLATE utf8_general_mysql500_ci NOT NULL,
`style` varchar(100) COLLATE utf8_general_mysql500_ci NOT NULL,
`member` text COLLATE utf8_general_mysql500_ci NOT NULL,
`zone` varchar(300) COLLATE utf8_general_mysql500_ci NOT NULL,
`region` varchar(100) COLLATE utf8_general_mysql500_ci NOT NULL,
`website` varchar(800) COLLATE utf8_general_mysql500_ci NOT NULL,
`image` varchar(2083) COLLATE utf8_general_mysql500_ci NOT NULL,
`user` varchar(700) COLLATE utf8_general_mysql500_ci NOT NULL,
`num` varchar(200) COLLATE utf8_general_mysql500_ci NOT NULL,
`registration` varchar(300) COLLATE utf8_general_mysql500_ci NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_general_mysql500_ci
EDIT 3:
<?php
require 'connection.php';
$user = mysqli_real_escape_string($con, $_POST["user"]);
$sql = "SELECT name, HEX(name) AS hex_name FROM tab where user='".$user."'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo $row["name"], ' ', $row["hex_name"], '.';
}
} else {
echo "0 results";
}
mysqli_close($con);
?>
result:
EDIT 4:
result with text:
in text:
׳׳‘׳’׳“
׳׳•׳¨ ׳¢׳§׳™׳‘׳
׳׳׳•׳ ׳™ ׳™׳¦׳—׳§
copied from console:
in database:
as hebrew text:
אבגד
אור עקיבא
אלוני יצחק
at the same time with another request in other page to same table and record, console:
in app:












