Welcome to our community

Be a part of something great, join today!

Html, css, javascript, php

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
I searched online and I found "set names utf8". Do we use this one? Or does it depend on the language we want to use? But how exactly is the code and where do we write this? Is this a part inside <?php ... ?> ? 🧐
 

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265
I searched online and I found "set names utf8". Do we use this one? Or does it depend on the language we want to use? But how exactly is the code and where do we write this? Is this a part inside <?php ... ?> ?
Typically we would have an array in php that translates each english word into the target language.
Then, whenever we echo a word to the user, we would look it up in this array first. 🤔
 

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
Typically we would have an array in php that translates each english word into the target language.
Then, whenever we echo a word to the user, we would look it up in this array first. 🤔
Only few words are not in english, the search button and some of the possible inputs.

The search button is displayed now as:
1617663391361.png

and when I give the non-english input they are not recognized althought these words are also in the php content file.

What do you mean to create an array. Should I write all the possible words in both languages? :unsure:
 

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265
Only few words are not in english, the search button and some of the possible inputs.
Which words? (Wondering)

The search button is displayed now as:
What are you displaying in the search button? (Wondering)

and when I give the non-english input they are not recognized although these words are also in the php content file.
Which php content are you matching with the search input? (Wondering)

What do you mean to create an array. Should I write all the possible words in both languages?
Which languages do you want to support?
Just Greek?
Is English a target language?
Are there other languages? (Wondering)
 

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
Which words? (Wondering)
If I write in the content.php file a greek word in place of "Phones" for example and then I give this word as an input in the searchbox, it is not identified and it gives the result that this input is not in the content file. But this happens only if I change "Phones" to an other word in greek. So it is related with the language, or not? 🧐


What are you displaying in the search button? (Wondering)
Inside the button part I write the word "Αναζήτηση" but the result is as I showed above. Do we have to define the greek language first? 🤔


Which php content are you matching with the search input? (Wondering)
I check if the input is one of the top level words of the content.php file. 🧐
 
Last edited:

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265
If I write in the content.php file a greek word in place of "Phones" for example and then I give this word as an input in the searchbox, it is not identified and it gives the result that this input is not in the content file. But this happens only if I change "Phones" to an other word in greek. So it is related with the language, or not?
To match the Greek version, we can can first do $language["Phones"] = " Τηλέφωνα".
And then match it with if ($deviceType == $language[$search]) { ... } instead of if ($deviceType == $search) { ... }. 🤔

Inside the button part I write the word "Αναζήτηση" but the result is as I showed above. Do we have to define the greek language first?
No. I believe it means that your .php file has the wrong encoding. (Shake)
It should be in UTF-8.
Which editor do you use to edit the .php file? (Wondering)
I use Notepad++, which has a menu option Encoding, which shows that it is encoded in UTF-8.

I check if the input is one of the top level words of the content.php file.
Do you only want so find exact matches for one of the top level words?
Or also if the search string occurs in for instance the description of a device? (Wondering)
 

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
To match the Greek version, we can can first do $language["Phones"] = " Τηλέφωνα".
And then match it with if ($deviceType == $language[$search]) { ... } instead of if ($deviceType == $search) { ... }. 🤔
Does this translation mean that if the at the content.php file we have "Phones"and if the input is "Τηλέφωνα" then it should be recognized as the same thing?
I don't mean it in this way. I mean that if in the content.php file I have a greek word, for example "Τηλέφωνα" and the input is "Τηλέφωνα" then I get a message that this product doesn't exist. But if I have in the content.php file the english word "Phones" and the input is "Phones" then I get the message that product exists. So the program desn't "understand" the greek language? 🤔


No. I believe it means that your .php file has the wrong encoding. (Shake)
It should be in UTF-8.
Which editor do you use to edit the .php file? (Wondering)
I use Notepad++, which has a menu option Encoding, which shows that it is encoded in UTF-8.
I use Notepad, and at "Save as"at EncodingIalsohae UTF-8. So shouldn't the greek letters be correctly encoded? 🤔



Do you only want so find exact matches for one of the top level words?
Or also if the search string occurs in for instance the description of a device? (Wondering)
Just in the top-level words.
 

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265
Does this translation mean that if the at the content.php file we have "Phones"and if the input is "Τηλέφωνα" then it should be recognized as the same thing?
I don't mean it in this way. I mean that if in the content.php file I have a greek word, for example "Τηλέφωνα" and the input is "Τηλέφωνα" then I get a message that this product doesn't exist. But if I have in the content.php file the english word "Phones" and the input is "Phones" then I get the message that product exists. So the program desn't "understand" the greek language?
Ah right. (Blush)
I meant it the other way around.
It should be if ($language[$deviceType] == $search) { ... }. 🤔

Alternatively, we could invert the translation and use for instance $english["Τηλέφωνα"] = "Phones". 🤔


I use Notepad, and at "Save as"at Encoding also has UTF-8. So shouldn't the greek letters be correctly encoded?[/icode]
I guess so... I tested it and it worked just fine for me.
That is, I have an action.php that is encoded in UTF-8 that echoes Greek text.
And my browser shows the Greek text correctly.

Suppose you right click on the page in the browser with the output of action.php, select Inspect Element, select the Console tab sheet, and reload the page .
Does it give any errors related to character encodings? (Wondering)
Now that I think about it, we should probably add <meta charset="UTF-8"> in the <head></head> section of the html page that action.php generates.
This w3schools page says that the default used to be the character set ISO-8859-1, so perhaps your browser uses that default.

Just in the top-level words.
There is only one, isn't there?
I've seen only "Phones".
Or are there more? (Wondering)
 
Last edited:

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
I think we need foreach($content as $deviceType => $deviceAttributes) for the top level. 🧐
Do we define this in this way because we have an array of arrays? Or in this way we define every array-element? 🤔
 

Klaas van Aarsen

MHB Seeker
Staff member
Mar 5, 2012
9,265
Do we define this in this way because we have an array of arrays? Or in this way we define every array-element?
It's not an array of arrays. (Shake)
Instead it's because the array is of the form [ key => value, key => value ] as opposed to [ value, value ]. 🤔

An array of arrays would be of the form [ [ value, value ], [ value, value ] ], but that is not what we have.
 

evinda

Well-known member
MHB Site Helper
Apr 13, 2013
3,829
It's not an array of arrays. (Shake)
Instead it's because the array is of the form [ key => value, key => value ] as opposed to [ value, value ]. 🤔

An array of arrays would be of the form [ [ value, value ], [ value, value ] ], but that is not what we have.
I understand!!! (Nod)