Hi,

I try to write a function to check if a string is in English or not
I use ctype_alnum which is fine as long as I don't have any spaces or numbers in the string.

Is there a better way to do so?

thanks!

    How is PHP supposed to know what's English and what's not? Take these two sentences:

    I like Taco Bell.
    Yo quiero Taco Bell.

    Now, explain in detailed logical steps how you can determine if those sentences are in English or not.

      sorry my mistake - didn't explain it right...
      I mean English chars.

      I want to check if the string is in Hebrew chars or Latin (A-Z

        bradgrafelman wrote:

        How is PHP supposed to know what's English and what's not?
        (...)
        Now, explain in detailed logical steps how you can determine if those sentences are in English or not.

        You might want to take a course on natural language processing so you can find out possible answers to your question 🙂

        scialom wrote:

        sorry my mistake - didn't explain it right...
        I mean English chars.

        I want to check if the string is in Hebrew chars or Latin (A-Z

        That is still not very clear. Do you want to check if the sentence contains letters of a certain alphabet? Do you want to check if (presumably after stripping punctuation and whitespace, and maybe ignoring numerals) the entire sentence only consists of letters of a certain alphabet?

          I may take this course 🙂

          here is what I want to do:
          the user has a text field to insert some text. If they write in English or other Latin language I want to insert it to a table
          if they write in Hebrew I want to insert it to a different table

          hope it is clear now 🙂

            scialom wrote:

            the user has a text field to insert some text. If they write in English or other Latin language I want to insert it to a table
            if they write in Hebrew I want to insert it to a different table

            Suppose they write in a mixture of English and Hebrew. Then what?

              you right but for this application all the user needs to do is insert their name. So they will do it either in Hebrew or in English

                Well... have you considered just asking the user (e.g., using a checkbox) whether the name is in Hebrew or English?

                  I want to solve it on the script - not let the user to choose

                    Right. One thing you could try is to use [man]preg_match/man to check if the string contains a letter from the English alphabet. If it does, assume the entire text is in English. If this does not work, you could try [man]mb_ereg_match/man.

                      Write a Reply...