PHP - Arabic Charset Encoding Problem?
Similar TutorialsHi How can I make the data in phpmyadmin accept Arabic Language. Now Arabic language shows as question markss ?????????????. Is there anyway to do this via php? hi i am calling some text from a database with php and echoing it to flash. i have no idea the charset anything is in. all i can see is that calling the text from the database and placing into flash yields in some missing chars, but if echo the called text to the browser, copy it and echo that to flash, all characters appear. now, i kow this is not a flash forum, and im not going to ask for a flash solution because there's just too many different charsets and code i cannot control/ nor see so i was thinking of doing something along the line of having php creating a clone of the copied text that appears in the browser, and having it echo that text to flash. it there something php can do, similar to what i described? regards Hi, I have few files which i need to display in correct format and also save in db to use. My problem is here is my code: $file = "C:\\file.txt"; $data = file_get_contents($file); $data = '<pre>'; $data .= mb_convert_encoding($file, 'UTF-8', 'ISO-8859-1'); $data .= '</pre>'; echo $data; but when i echo $data i get weird characters . here is result http://paste2.org/p/1361878 Thanks for any help. Hello everybody, Hope somebody can help. As the subject says, I'm having encoding problems in my includes files, the "accents" and some special characters don't work. However, they do work in my main HTML. I really don't know what the problem is and how to fix it. Thanks in advance. Hi, Using arabic characters, I have a project, in the admin panel, where i am trying to change the value in the text box(ajax) on onblur js function. Firefox simply working great but i am getting square brackets in the text box in the browser ie. I simply guessing the value from the text box is not in the form of utf-8 encoding, i am calling the external javascript file, this is the code am using.. Code: [Select] // JavaScript Document var xmlhttp; //function namechange(name_fieldvalue) function namechange(name_fieldvalue,name_fieldname,id_val,id_fieldname,table_name) { /* alert(name_fieldvalue); alert(name_fieldname); alert(id_val); alert(id_fieldname); alert(table_name); */ if (name_fieldvalue.length==0) { document.getElementById("txtHint").innerHTML=""; return; } xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Your browser does not support XMLHTTP!"); return; } var url="ajax_namechange.php"; url=url+"?name_fieldvalue="+name_fieldvalue; url=url+"&name_fieldname="+name_fieldname; url=url+"&id_val="+id_val; url=url+"&id_fieldname="+id_fieldname; url=url+"&table_name="+table_name; xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } Anyone has the idea on this, please help me. Thanks, I submit text to my MySQL database using a form on my site. When I look at the text in my database, sometimes, there are strange characters. The strange characters are caused by quotation marks, em dashes, apostrophes and foreign letters of the alphabet. I think that this only happens when the source of the text is a Windows program. I understand that this is a character encoding issue, but I don't fully understand the subject. I've spent the last few hours researching it, but it's only confused me.
My site uses UTF-8 encoding:
<meta http-equiv="content-type" content="text/xml; charset=utf-8" />The collation of my database is utf8_general_ci. My form looks like this: <form action="" method="post"> </form>As you can see, an accept-charset="utf-8" attribute has not been specified. Questions 1) I am guessing that my problem is that the Windows characters are being misinterpreted by my UTF-8 setup. Is that correct? 2) If so, is there a way that I can safely convert the Windows characters to UTF-8 during the submission process? 3) Should I also specify an accept-charset="utf-8" attribute on the form? 4) When I paste the Windows text directly into my database without using the form, the characters save without turning into the strange characters. But they don't render properly on my site. Can't browsers identify Windows characters? Hi, I am generating certificates in php i can display the name in arabic but it will not print on the certicate. It can show the English names though! is there a special code to be able to show that? code: <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous"> <title>Certificate Generator</title> </head> <body> <center> <br><br><br> <h3>Certificate Generator</h3> <br><br><br><br> <form method="post" action=""> <div class="form-group col-sm-6"> <input type="text" name="name" class="form-control" id="name" placeholder="Enter Name Here..."> </div> <button type="submit" name="generate" class="btn btn-primary">Generate</button> </form> <br> <?php if (isset($_POST['generate'])) { $name = strtoupper($_POST['name']); $name_len = strlen($_POST['name']); if ($name == "" ) { echo " <div class='alert alert-danger col-sm-6' role='alert'> Ensure you fill all the fields! </div> "; }else{ echo " <div class='alert alert-success col-sm-6' role='alert'> Congratulations! $name on your excellent success. </div> "; //designed certificate picture $image = "certi.png"; $createimage = imagecreatefrompng($image); //this is going to be created once the generate button is clicked $output = "certificate.png"; //then we make use of the imagecolorallocate inbuilt php function which i used to set color to the text we are displaying on the image in RGB format $white = imagecolorallocate($createimage, 205, 245, 255); $black = imagecolorallocate($createimage, 0, 0, 0); //Then we make use of the angle since we will also make use of it when calling the imagettftext function below $rotation = 0; //we then set the x and y axis to fix the position of our text name $origin_x = 200; $origin_y=240; //we then set the x and y axis to fix the position of our text occupation $origin1_x = 120; $origin1_y=90; //we then set the differnet size range based on the lenght of the text which we have declared when we called values from the form if($name_len<=7){ $font_size = 25; $origin_x = 190; } elseif($name_len<=12){ $font_size = 30; } elseif($name_len<=15){ $font_size = 26; } elseif($name_len<=20){ $font_size = 18; } elseif($name_len<=22){ $font_size = 15; } elseif($name_len<=33){ $font_size=11; } else { $font_size =10; } $certificate_text = $name; //font directory for name $drFont = dirname(__FILE__)."/developer.ttf"; //function to display name on certificate picture $text1 = imagettftext($createimage, $font_size, $rotation, $origin_x, $origin_y, $black,$drFont, $certificate_text); imagepng($createimage,$output,3); ?> <!-- this displays the image below --> <img src="<?php echo $output; ?>"> <br> <br> <!-- this provides a download button --> <a href="<?php echo $output; ?>" class="btn btn-success">Download My Internship Certificate</a> <br><br> <?php } } ?> </center> <footer> <center><p>Built with ❤ by <a href="https://olawanlejoel.github.io/portfolio/">Olawanle Joel</a></p></center> </footer> <!-- Optional JavaScript --> <!-- jQuery first, then Popper.js, then Bootstrap JS --> <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script> <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script> </body> </html> Edited May 22, 2020 by ramiwahdan typo error Hello all, Just started learning a bit of PHP from resources i can find over the net. I am working on a mail form and it works perfectly with the english text. no errors or issues. But when i type in arabic my outlook receives it as : فات ثيات سثسقغتن غتن فغثتن ثغ ثغن صف يفغن فغ ن صفغن ثعغ صتنفغت صنثفع Could anyone point out where my problem is please ? Thanks in advance and appreciate yoru help guys. Cheers. HTML - test.html Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Form</title> <link href="style_form.css" rel="stylesheet" type="text/css" /> </head> <body> <form id="form1" name="form1" method="post" action="test.php"> <table width="830" border="0" cellspacing="0" cellpadding="5"> <tr> <td height="78" colspan="2" valign="top" background="images/fheader.jpg"><p> </p> <p> </p></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid; border-top: 8px white solid;"><strong>Name: *</strong></td> <td style="border-bottom: 2px white solid; border-top: 8px white solid;"><textarea name="name" cols="58" rows="1" id="name"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Occupation: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="occupation" id="occupation" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Nationality: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="nationality" cols="58" rows="1" id="nationality"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Country of residence: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="country" id="country" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Telephone number: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="telephone" id="telephone" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Email address: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="email" id="email" cols="58" rows="1"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments:</strong> *</td> <td style="border-bottom: 2px white solid;"><textarea name="j" id="j" cols="58" rows="4"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments about us: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="jd" id="jd" cols="58" rows="4"></textarea></td> </tr> <tr > <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Comments about the website: *</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="website" id="website" cols="58" rows="4"></textarea></td> </tr> <tr> <td width="300" valign="top" style="border-bottom: 2px white solid;"><strong>Other information you wish to provide:</strong></td> <td style="border-bottom: 2px white solid;"><textarea name="other" id="other" cols="58" rows="4"></textarea></td> </tr> <tr> <td valign="top"> </td> <td><input type="submit" name="Submit" id="Submit" value="Submit" /> <input type="submit" name="Reset" id="Reset" value="Reset" /></td> </tr> </table> </form> </body> </html> PHP - test.php <?php if(isset($_POST['Submit'])) { $to = "email@email.com"; $subject = "Feedback [Arabic]"; $name_field = $_POST['name']; $occupation_field = $_POST['occupation']; $nationality_field = $_POST['nationality']; $country_field = $_POST['country']; $telephone_field = $_POST['telephone']; $email_field = $_POST['email']; $j_field = $_POST['j']; $jd_field = $_POST['jd']; $website_field = $_POST['website']; $other_field = $_POST['other']; $headers = "MIME-Version: 1.0 \n" ; $headers .= "Content-Type: text/plain;charset=UTF-8 \n"; $body = mb_convert_encoding($body, "UTF-8","AUTO"); mb_language("uni"); $body = "Name: $name_field\n\n Occupation: $occupation_field\n\n Nationality: $nationality_field\n\n Country of residence: $country_field\n\n Telephone: $telephone_field\n\n Email: $email_field\n\n Comments: $j_field\n\n Comments about us: $jd_field\n\n Comments about website: $website_field\n\n Other information: $other_field\n\n"; mb_send_mail($to, $subject, $body); } else { echo "error: no data sent!"; } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Sending...</title> <meta http-equiv="refresh" content="1;url=fthankyou_ar.html"> <meta http-equi </head> <div align="center"> <p><img src="/images/loadbar.gif" width="232" height="11"></p> <p><b>Prcessing and redirecting ...</b></p> </div> </body> </html> I have created a Post php form, It send two emails, One email to the user after they submit the form and other to me. Now the users will fill up the form in arabic and a confirmation email will be sent to them in arabic also...I tested my form, I get the confirmation email in arabic, its fine, but the data tht the user inputs in arabic on the form comes to my email with strange characters.....i want to receive the data entered by user in arabic. Below is the HTML and Php Here is my HTML Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="ar" xml:lang="ar" xmlns="http://www.w3.org/1999/xhtml"> <head> <link href="../../css/cssfinal.css" type="text/css" rel="stylesheet"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Language" content="ar"> <title>Untitled Document</title> <style type="text/css"> <!-- body { background-color: #FFFFFF; } .style8 {color: #FF0000} --> </style> <script src="../../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <script src="../../SpryAssets/SpryValidationSelect.js" type="text/javascript"></script> <link href="../../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <link href="../../SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" /> </head> <body> <table align="center" width="547" border="0" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> <tr> <td> </td> </tr> </table> <form method="post" name="enquiry" action="sendmailsqlar.php"> <table width="547" align="center" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="101" background="../../images/formhead.png"><div align="center" class="status" style="margin-bottom:20px; margin-top:20px">نموذج الاستفسار عن الدورة الأكاديمية</div></td> </tr> </table> <table width="547" border="0" align="center" cellspacing="0" cellpadding="0"> <tr> <td width="275"><div align="right"><input name="Name" type="text" id="visitor" value="" size="36" class="field" /></div></td> <td width="272" align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">الاسم</div> <span id="sprytextfield1"><span class="textfieldRequiredMsg">مطلوب</span></span></div></td> </tr> <tr> <td><div align="right"><input name="Email" type="text" id="visitormail" size="36" class="field" /></div></td> <td align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">البريد الإلكتروني</div> <span id="sprytextfield2"><span class="textfieldRequiredMsg">مطلوب</span><span class="textfieldInvalidFormatMsg">غير صحيح </span></span></div></td> </tr> <tr> <td><div align="right"><input name="Nationality" type="text" id="nationality" size="36" class="field" /></div></td> <td align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">الجنسية</div> <span id="sprytextfield2"><span class="textfieldRequiredMsg">مطلوب</span></span></div></td> </tr> <tr> <td align=""><div align="right"> <select name="Level" id="stulevel" size="1" class="select"> <option value=""><span class="drop.Text">(إختر)</span></option> <option value=" Foundation/Diploma ">دبلوم</option> <option value=" Bachelor Degree ">البكالوريوس</option> <option value=" Master Degree ">ماجستير</option> <option value=" PhD./Others ">دكتوراه</option> </select> </span></div></td> <td align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">المرحلة الدراسية المطلوبه</div> <span id="spryselect1"><span class="selectRequiredMsg">مطلوب</span></span></div></td> </tr> <tr> <td><div align="right"><input name="Field" type="text" id="stfield" size="36" class="field" /></div> </td> <td align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">مجال الدراسة \ التخصص</div> <span id="sprytextfield3"><span class="textfieldRequiredMsg">مطلوب</span></span></div></td> </tr> <tr> <td colspan="2"><table width="547" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="275"><label> <div align="right"><textarea name="Message" style="background-color:#ccc2b2" class="field" id="message" cols="27" rows="6"></textarea></div> </label></td> <td width="272" align="right"><div style="margin-left:25px; margin-bottom:10px; margin-top:10px; font-size:18px;"> <div style="margin-right:25px;">ملاحظات</div> </div></td> </tr> </table></td> </tr> <tr> <td colspan="2" height="101" background="../../images/formfoot.png"><div align="center" style="margin-top:15px"> <input type="submit" class="btn1" value="إرسال" /> </div></td> </tr> </table> </form> <script type="text/javascript"> <!-- var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1"); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4"); //--> </script> </body> </html> Here is the PHP Code: [Select] <html dir="rtl"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Language" content="ar"> </head> <?php $to = "xx@xxx.com"; $visitor = $_REQUEST['Name'] ; $visitormail = $_REQUEST['Email'] ; $nationality = $_REQUEST['Nationality'] ; $stulevel = $_REQUEST['Level'] ; $stfield = $_REQUEST['Field'] ; $message = $_REQUEST['Message'] ; $header = "From: $visitormail\n" . "Reply-To: $visitormail\n"; $subject = "Arab Enquiry"; $message = "From: $visitor \n\n Email: $visitormail \n\n Nationality: $nationality \n\n Level: $stulevel \n\n Field: $stfield \n\n Message: $message"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to, $subject, $message, $header); //Sending auto respond Email to visitor $reply_header = "From: ttt@ttt.com\n" . "Reply-To: vvv@vvv.com\n"; $reply_subject = " - تم استلام طلبكم"; $reply_to = "$visitormail"; $reply_message = "$visitor \n\n شكرا لزيارتكم موقعنا . \n نود ابلاغكم بأنه تم استلام طلبكم وسوف يتم الرد عليكم قريبا.\n هذه الرسالة مرسلة من نظام الموقع.\n شكرا\n ."; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($reply_to, $reply_subject, $reply_message, $reply_header); header("Location: thankyouar.html"); ?> please help !!!! i would appreciate hi all .. I want to write arabic text in image .. this is my code .. <?php header("Content-Type: image/png; charset=utf8"); $im = imagecreatetruecolor(150, 30); // Create some colors $white = imagecolorallocate($im, 100, 255, 255); $grey = imagecolorallocate($im, 128, 128, 128); $black = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, 399, 29, $white); $font = 'tahoma.ttf'; $t = 'إن الدين عند الله الإسلام'; $text=utf8_encode($t); imagettftext($im, 20, 0, 10, 20, $black, $font, $text); imagepng($im); imagedestroy($im); ?> Hi, When I post Arabic articles to my new blog, the alignment of text is like English so how can I align the text to be from right to left. as shown below: http://www.blog.aiwwan.com/ Anyone know how to cast arabic numeric input to (int) ? Or how to convert arabic numerals to english numerals? I created an auction website, inputting english numbers seems to work. However when I switch languages to Arabic, it doesn't work. By casting any arabic numeral input to (int) It keeps returning 0. ١٢٣٤٥٦٧٨٩ 123456789 hi, i made my own page, but when i do an insert using mysql, jquery and php, the arabic text does not show properly it is a comments page. here is the DB structure Code: [Select] CREATE TABLE IF NOT EXISTS `app_comments` ( `comment_id` int(20) NOT NULL auto_increment, `comment` text NOT NULL, `user_id` int(20) NOT NULL, `comment_date` date NOT NULL, `app_id` int(20) NOT NULL, PRIMARY KEY (`comment_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=35 ; here is the jquery piece that transfers to php code. Code: [Select] function submit_comment(){ $(".post_comments_button").click(function() { var post_comments = $('.post_comments').val(); var app_id = $('#app_id').val(); //alert (app_id); if(confirm('Add Comment?')) { var string = "task=add_comment&app_id=" + app_id + "&comment="+post_comments; $.ajax({ url : "appajax.php", type : "POST", data : string, success : function(data) { alert(data); window.location.reload(true); } }); } /**/ }); }and here is the acutal insert code in php $new_appquery = 'INSERT INTO app_comments (comment, user_id, app_id,comment_date) VALUES ("' . $comment . '",' . $user_id . ', ' . $app_id . ',NOW());'; and the actual problem is, the arabic text shows like this in my application: Quote بالتوفيق للريال how can i solve this issue? When using this form to send emails I got symbols in my emails (especially when typing Arabic characters) ? for the English characters it's OK http://www.blog.aiwwan.com/contact.php Hi, i have export the search result to excel file, but arabic characters not displaying properly in excel file, eventhough i mention the header content type as utf-8 here my code... Code: [Select] <?php include("global.php"); // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } $sql = $_SESSION['emp_search_sql']; // file name for download $filename = "employees_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); header("Pragma: no-cache"; $flag = false; $result = $DB_site->query($sql) or die('Query failed!'); while(false !== ($row = mysql_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> Thanks, |