3

I have a problem with jQuery ajax in sending information.

The PHP code is supposed to detect Hebrew letters and convert them to Arabic letters according to the transcription rules.

this is my code (jQuery code):

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                $("#input").keyup(function() {
                    var input = $("#input").val();
                    $("#text").load("changetext.php", {input:input});
                });
            });
        </script>
    </head>
    <body dir="rtl">
        <center>
            <input type="text" id="input" />
            <div id="text"></div>
            <button id="go">חפש!</button>
        </center>
     </body>
</html>

And this is the PHP page (where the conversion of letters occurs):

<?php

$input = $_POST['input'];

str_replace("א", "ا", $input);
str_replace("ב", "ب", $input);
str_replace("ג'", "ج", $input);
str_replace("ד", "د", $input);
str_replace("ד'", "ذ", $input);
str_replace("ה", "ه", $input);
str_replace("ו", "و", $input);
str_replace("ז", "ز", $input);
str_replace("ח", "ح", $input);
str_replace("ח'", "خ", $input);
str_replace("ט", "ط", $input);
str_replace("ט'", "ظ", $input);
str_replace("י", "ي", $input);
str_replace("כ", "ك", $input);
str_replace("ל", "ل", $input);
str_replace("מ", "م", $input);
str_replace("נ", "ن", $input);
str_replace("ס", "س", $input);
str_replace("ע", "ع", $input);
str_replace("פ", "ف", $input);
str_replace("צ", "ص", $input);
str_replace("ק", "ق", $input);
str_replace("ר", "ر", $input);
str_replace("ש", "ش", $input);
str_replace("ת", "ت", $input);
str_replace("ת'", "ث", $input);
str_replace("ס'", "ض", $input);
str_replace("ט'", "ظ", $input);
str_replace("ר'", "غ", $input);
str_replace("א'", "ﺀ", $input);

echo $input;
?>

This code don't work, and I don't know why.

secretformula
  • 6,414
  • 3
  • 33
  • 56
Hagaymosko
  • 51
  • 7

2 Answers2

0

I think you got some encoding problems

Go Here.

Taking from the link

this is the answer that was required but everybody answered only part one of many

Step 1

  • You cannot have the multilingual characters in unicode document.. convert the document to UTF-8 document

advanced editors don't make it simple for you... go low level... use notepad to save the document as meName.html & change the encdoing type to UTF-8

Step 2

Mention in you html page that you are going to use such characters by

meta http-equiv="Content-Type" content="text/html;charset=UTF-8" >

Step 3

  • When you put in some characters make sure your container tags have the following 2 properties set

    dir='rtl' lang='ar'

Step 4

  • Get the characters from some specific tool\editor or online editor like i did with Arabic-Keyboard.org

example

رَبٍّ زِدْنٍي عِلمًا

NOTE: font type, font family, font face setting will have no effect on special characters

Community
  • 1
  • 1
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
0

I think that what you're trying to do is probably not going to be very efficient. The load() method requires a round trip to the server and is asynchronous to boot so the update to the text div won't necessarily correspond to the user keystrokes. It seems to me that you should either:

  1. Not use the keyup event, if possible, and do the load once. OR
  2. If you want to have the immediate feedback, do all the work client-side.

Here's an example of the latter:

$( document ).ready(function() {
    var replacements = {ا: '\u05D0', ب: '\u05D1', ج: '\u05D2\u05F3', د: '\u05D3', ذ: '\u05D3\u05F3', ه: '\u05D4', و: '\u05D5', ز: '\u05D6', ح: '\u05D7', خ: '\u05D7\u05F3', ط: '\u05D8', ظ: '\u05D8\u05F3', ي: '\u05D9', ك: '\u05DB', ل: '\u05DC', م: '\u05DE', ن: '\u05E0', س: '\u05E1', ع: '\u05E2', ف: '\u05E4', ص: '\u05E6', ق: '\u05E7', ر: '\u05E8', ش: '\u05E9', ت: '\u05EA', ث: '\u05EA\u05F3', ض: '\u05E1\u05F3', ظ: '\u05D8\u05F3', غ: '\u05E8\u05F3', ﺀ: '\u05D0\u05F3'};
    $('#input').keyup(function() {
        var input = $('#input').val();
        var txt = input.replace(/./g, function(char) {return char in replacements ? replacements[char] : char})
        $('#text').text(txt);
    });
});

EDIT

I finally figured out an rtl example using your character map. Basically, I created an associative array, using unicode values for the Hebrew characters. The array is used to replace the characters from the input val. Then the text() method from jQuery is used to update the #text div. Seems to work well, though admittedly, I don't know anything about Arabic or Hebrew, so I can't really determine if it's accurate.

Here's a working fiddle if you want to see it in action.

jme11
  • 17,134
  • 2
  • 38
  • 48