special characters french accents - php

We are fetching data from csv file through php, and trying to compare data to insert the right data in our database but php comparison is not working as data in file is with french accents.
Here is a piece of code we are working with.
if($data[0]=='Expression' && $data[1]=='Domaine (Domain)' && utf8_decode($data[2])==utf8_decode('DŽfinition (Definition)') && $data[3]=='Commentaire (Commentary)' && $data[4]=='Voir aussiÉ (See also É)' && $data[5]=='ƒquivalent anglais (English equivalent)' && $data[6]=='En contexte / exemple(s) É (In context / examples)' && $data[7]=='Source' )
{
echo "<tr>
<td>".$data['0']."</td>
<td>".$data['1']."</td>
<td>".$data['2']."</td>
<td>".$data['3']."</td>
<td>".$data['4']."</td>
<td>".$data['5']."</td>
<td>".$data['6']."</td>
<td>".$data['7']."</td>
<td><i class='fa fa-close text-navy'></i></td>
</tr>";
return true;
}
else
{
echo "invalid data";
exit;
}
We have tried with this as well.
function convert($data)
{
$value = utf8_encode($data);
$value = iconv('UTF-8', 'ASCII//TRANSLIT', $value);
return $value;
}
Header is already placed output is fine
header('Content-Type: text/html; charset=iso-8859-1');
We have tried with several php functions like utf_decode,html entities, html special char, htmlspecialchar_decode but nothing is working.
echo print_r(utf8_decode($data[2]));
output is as following:
D?finition (Definition)1invalid data
Actual word is : DŽfinition (Definition)'
We are working on french dictionary and need to do real time searching on the data as well, please help with mysql as well, like which functions are needed to be called before insertion for decoding and which functions are needed to be called before showing data back to user encoding!
Hope my question is bit clear.
Thanks in advance

To save the CSV in UTF8, open it in notepad.
And Go to File - Save As
Change the Encoding to UTF-8.
or with Libre Office :
https://csvimproved.com/support/questions-and-answers/916-save-a-csv-file-as-utf-8
Hope it ll help

Related

Is there a way to check existence of arabic character like sukum( ۡ ) in a string which primarily comes attached to other characters

So far I have tried to check existence with string position function after even encoding to utf-8 but fails as following
$a="بِسۡمِ";
$a=mb_convert_encoding($a,"UTF-8","auto");
if (strpos($a, ' ۡ') !== false) {
echo 'exists';
}
else{
echo"does not exist"
}
and if possible to replace it with other forms such as ⟨ˆ⟩ or ⟨ʼ⟩
anyone with any idea will be appreciated. I am not an Arabic speaker nor Arabic background.

Emoji name "family_mothers_one_boy" or "woman-woman-boy"?

I have a reference emojis file used by my php code. Inside there is for example "woman-woman-boy", but the browser (chrome) replaces this name by "family_mothers_one_boy"...
Why are there two versions of emojis' names?
Is there en (some) error(s) in my file, or should I have to do something in my code to avoid the conversion?
NOTE:
The code related to this emoji is:
1F469;‍👩‍&#x1F466
Here are the two functions I'm using to manage the emojis:
1. When I display the emoji, I replace the tage :name: by the HTML rendering (using unicode)
function replaceEmojiNameByUnicode($inputText){
$emoji_unicode = getTabEmojiUnicode();
preg_match_all("/:([a-zA-Z0-9'_+-]+):/", $inputText, $emojis);
foreach ($emojis[1] as $emojiname) {
if (isset($emoji_unicode[$emojiname])) {
$inputText = str_replace(":".$emojiname.":", "&#x".$emoji_unicode[$emojiname].";", $inputText);
}
else {
$inputText = str_replace(":".$emojiname.":", "(:".$emojiname.":)", $inputText);
}
}
return $inputText;
}
2. When I want to propose the list of emoji I display an HTML SELECT in the page. Teh following function return the list of option to add inside:
/* Display the options in the HTML select */
function displayEmojisOptions(){
$emoji_unicode = getTabEmojiUnicode();
foreach ($emoji_unicode as $name => $unicode) {
echo '<option value="&#x'.$unicode.';">'.$name.' => &#x'.$unicode.';</option>';
}
}
In the array $emoji_unicode there is one entry (with 3 semi-column removed to not display emoji here):
'family_one_girl' => '1F468;&#x200D&#x1F469&#x200D&#x1F467',
For example: In order to make it works, I have to replace the line 'thinking_face' => '1F914', by 'thinking' => '1F914',
My question is: why ??
Thank you
Nop, the emoji text was changed by no code... I guess it was due to a wrong emoji file I used... I correct all the emoji manually and now I did not see the mismatch anymore...
If someone need the corrected file, I can provide it.

turkish/hungrairan/ polish letters not executing properly

I'm a bit of a novice here so my apologies if I didnt derive this answer from earlier posts I read.
I put together a file in php. Everything works when the URL to the php file is executed, except some of the Polish and Turkish characters come up as question marks (in utf8 and unicode) and simply disappear and turn into latin letters in anicode.
i edited both in wordpad and notepad.
How can I fix this problem, please?
thanks.
function array_utf8_encode($dat)
{
if (is_string($dat))
return utf8_encode($dat);
if (!is_array($dat))
return $dat;
$ret = array();
foreach ($dat as $i => $d)
$ret[$i] = array_utf8_encode($d);
return $ret;
}
header('Content-Type: application/json');
// Return the array back to Qualtrics
print json_encode(array_utf8_encode($returnarray));
?>
Sounds like you might need to add the json_encode JSON_UNESCAPED_UNICODE option:
print json_encode(array_utf8_encode($returnarray), JSON_UNESCAPED_UNICODE);
Other json_encode options are at: http://php.net/manual/en/json.constants.php

php strstr not detecting substring in a arabic string

Can anyone please tell me ,How to make string matching function work with Arabic keywords?
The Following keywords are detected as Unmatched in php. Though these are matching in normal browser searching.
if (strstr('الهيئة العامة للقوى العاملة', 'قوى العامله') != false) {
echo'in';
} else {
echo'out';
}die;
Result comes as 'out'.
Thanks
Try this .. I have PHP Version 5.6.23
<?php
$string = 'الهيئة العامة للقوى العاملة';
$find_me = 'قوى العاملة';
if (strstr($string, $find_me) != false) {
echo'in';
} else {
echo'out';
}die;
?>
You can see output here https://eval.in/764085
The result for the match you are doing should be out, so it's working just fine for you. There is no match for the search you are doing since the last letter in the word العاملة is different between the two strings.
Try to re-save the page in
UTF-8 Wihtout Bom
this work for me

Some Japanese characters not displaying correctly

I'm having a problem where I'm trying to parse an email, and then post the email content to a website. The email may contain Japanese or English. The Japanese displays 99% correctly on the website, but every now and then a character will be swapped for another, or it will display as garbage.
Here's the code being used to get the proper encoding for the email body-
$post->content = quoted_printable_decode($parser->getMessageBody('text'));
$isISO2022 = $parser->isISO2022();
$post->content = ($isISO2022)
? mb_convert_encoding($post->content, 'UTF-8', 'iso-2022-jp')
: mb_convert_encoding($post->content, 'UTF-8', mb_detect_encoding($post->content));
$post->save();
The parser's isISO2022 function:
public function isISO2022() {
$isISO2022 = false;
foreach ($this->parts as $part) {
if (isset($part['headers']['content-type']) && preg_match('/iso-2022-jp/i',$part['headers']['content-type'])) {
$isISO2022 = true;
}
}
return $isISO2022;
}
Anyone have any ideas what's going on?
Added:
I have heard that there are some specific characters that are not supported by iso-2022-jp, and you should use iso-2022-jp-ms instead, but when I try to use iso-2022-jp-ms, it says invalid encoding. It also seems to me that the characters I've seen it not display correctly are basic characters, and should be universally supported.

Categories