Bad encoding when renaming html file to php - javascript

I had a file index.html with accents, and everything went fine.
Since I changed it for index.php, I see encoding problems. So I replaced accent with HTML entities in index.php and it displays well.
My last problem now is I have a form where inputs have custom placeholders fill in javascript, containing accents. Even with html entities these placeholders are displayed with encoding problem. How can I resolve this ?
In my index.php I have :
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
And in firebug I have :
Content-Type text/html; charset=iso-8859-1

When you're saving your file in text editor choose "Save As" usually you can choose encoding, for example in windows NotePad...
in Sublime you can choose "Save with encoding"
in PSPAD you have to click on Format and choose encoding before saving...
Notepad++ i found this didn't checked it "In Notepad++ 5.9 there is an option in Settings -> Preferences -> New Document/Default Directory to automatically convert ANSI files to UTF-8 without BOM on open"

Related

Display UTF8 and ISO-8859-1 in select box HTML

Hello, Folks!
All my script files are utf8, the server responses are utf8, the db collation.. quite everything.
I have a JSON data that populates the options of a select box. When I fix ISO I get in trouble in UTF8, or vice versa.
The point is: How can select option display both ISO-8859-1 and UTF-8 special chars?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<select id="values" name="values">
<option>VALÊNCIA 18</option>
<option>BAHRAIN ‫البحرين‬‎ 40</option>
</select>
</body>
</html>
I think it is not possible. But as in http://www.w3schools.com/tags/att_a_charset.asp this is possible but not supported by any popular browser, and it is obsolete in HTML5, so you should not use it.
As an alternate, you can convert non-Unicode text to UTF-8 using server-side script (PHP, ASP.net,...).
PHP ----> UTFString= utf8_encode ( ISO_String)
ASP.NET ----> utf8_encode= Encoding.GetEncoding(28591).GetBytes(ISO_String);
https://msdn.microsoft.com/en-us/library/zs0350fy%28v=vs.90%29.aspx
Hopefully you will find this helpful
[SOLVED] If any one had the same problem as me and the charset was already correct, simply do this:
Copy all the code inside the .html file.
Open notepad (or any basic text editor) and paste the code.
Go "File -> Save As"
Enter you file name "example.html" (Select "Save as type: All Files (.)")
Select Encoding as UTF-8
Hit Save and you can now delete your old .html file and the encoding should be fixed

Remove ms word 2013 formatting from text

How do I escape AutoFormatting code from MS Word 2013 copied contents before persistance?
For instance, on persisting ‘this should be ok’ becomes ���this should be ok��� when rendered on the screen.
On the server side it shows as âPADSOSthis should be okâPADSGCI.
I had to disable autoformat feature in word to resolve this issue. I tried both ISO-8859-1 and UTF-8 encoding without luck. Its a java based web application.
I am setting the charset type as UTF-8 in the html file.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

Javascript with UTF-8 encoding (in PHP form)

I have a web form which submits the comment to a predefined mail when the userfills it and clicks submit button, this is done using my Send.php file which includes all the codes needed to submit the comment with correct content and encoded with utf-8. everything works fine, however, after this procedure I included in the php file the JS code which popups the Alert windows, saying that the mail is sent, and after clicking OK button it redirects to the homepage.
this is a code:
echo '<script type="text/javascript">;
alert("კომენტარი გაიგზავნა წარმატებით, გმადლობთ");
</script>';
echo '<script type="text/javascript">
window.location = "http://g-projects.net78.net/index.html";
</script>'
However, because the alert text is in foreign language I get various unreadable symbols. I need to use utf-8 encoding, but how can I integrate it with this code? note that this code is called in PHP file.
Tell your text editor to edit your source file in utf-8.
Note that "კომენტარი გაიგზავნა წარმატებით, გმადლობთ" is a literal, so it is embedded in your php source file.
For example, in Notepad++ set: Encoding | Encode UTF-8.
(It already seems you have your html thinking it is outputting UTF-8, I hope.)
The system font for displaying message boxes is Segoe UI or Tahoma, by default, on Windows systems and Deja-Vu Sans or simply "Sans" on Linux systems. These fonts do not have the codes or the characters necessary to support the display of Indic text. In order to display text in that language your system's default UI font needs to have those characters encoded.
Also, just an aside: UTF-8 documents can be preambled, which means the byte-order-mark is given which tells the text processor to explicitly scan for a specific encoding. For UTF-8 three bytes EF BB BF signify text encoding. Do NOT use the preamble when saving PHP files. If you read the Unicode spec carefully, UTF-8 is designed not to be used with a preamble. But if you must add it, add it as an 'echo' from the PHP script before any other output, but do not start the PHP script file that way. (Just in case you run across this in your Unicode travels)

how to inject chinese characters using javascript?

I have this code but it only works using english characters
$( "input[name*='Name']" ).attr("placeholder","姓名");
My web page displays other chinese characters just fine and if I change the chinese characters to "Name", it starts working again just fine. Is there something special I have to do here?
In the header, I do see this as the encoding...
<meta http-equiv="content-type" content="text/html; charset=utf-8">
If the script is inline (in the HTML file), then it's using the encoding of the HTML file and you won't have an issue.
If the script is loaded from another file:
Your text editor must save the file in an appropriate encoding such as utf-8 (it's probably doing this already if you're able to save it, close it, and reopen it with the characters still displaying correctly)
Your web server must serve the file with the right http header specifying that it's utf-8 (or whatever the enocding happens to be, as determined by your text editor settings). Here's an example for how to do this with php: Set HTTP header to UTF-8 using PHP
If you can't have your webserver do this, try to set the charset attribute on your script tag (e.g. <script type="text/javascript" charset="utf-8" src="..."></script> > I tried to see what the spec said should happen in the case of mismatching charsets defined by the tag and the http headers, but couldn't find anything concrete, so just test and see if it helps.
If that doesn't work, place your script inline

Textbox with UTF-8 input

I am in the process of internationalizing a website, and I need to allow for a user to input Chinese characters into a search textbox. This text will end up being analyzed on the backend, so I need to ensure that I can accept the text encoded as UTF-8 via javascript (everything is done through AJAX). For testing purposes, I have an alert box being popped up with the text I enter every time a search is done, and when some Chinese text is entered in, I get 'undefined' returned. With English the word I entered is returned back, as expected. How can I ensure that all text in the textbox is encoded with UTF-8?
Make sure of the following:
Your HTML and JS documents are UTF-8 encoded.
You are sending a Content-type header with appropriate (UTF-8) value for both your HTML and JS files.
The meta tag charset defined in your HTML is also, appropriately, UTF-8.
Avoid using the built-in escape method; it is not UTF-8 (multibyte character) aware.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
html5
<meta charset="UTF-8" />
this will encode the entire page.

Categories