Alert Arabic letters display garbage in chrome - php

When I try that line:
echo "<script >alert(' مشترك بالفعل!'); location.href='index.php';</script>";
in chrome it display garbage but firefox display it correctly. What's wrong with chrome?
Any help will be appreciated. Thanks!

That is because, firefox rockssss – The COMPLETE PHP Newbie 47 secs ago
That comment is probably right (although maybe accidentally. :) Firefox may be sniffing the document's encoding with more flexibility than Chrome is.
The most likely explanation is that your HTML document's encoding is not defined, and the PHP source file (where you store the text in) is stored in a different encoding than you are outputting.
Make sure the encoding of the PHP file, and the HTML document you're outputting, match.
The encoding of the PHP source file can probably be set in your IDE
The encoding of the HTML page is defined by the Content-type header your web server sends, and/or the Content-type META tag.
This question gives a complete overview: UTF-8 all the way through

Related

PHP session with UTF-8-BOM encoding

I have created one php page with UTF-8-BOM encoding. I want to use this encoding because I have some content which are in my regional language, and do display it properly i need to use UTF-8-BOM encoding.
Now I want to use session with this page but it is throwing error of headers already set.
So is there any way i can use both together.
If I am trying to use UTF-8 only I am not getting problem displaying data in regional format.
See Attached Image
The "Byte Order Mark" is a sequence of 3 bytes that a file begins with, making it pretty much incompatible with PHP, because a script that is supposed to contain only PHP code must start with the <?php tag instead.
Obviously, it's not like the whole thing doesn't work at all, but anything that involves sending HTTP headers (which is A LOT) automatically gets broken.
Sessions use cookies - transferred via headers - won't work.
Redirecting to another page - the Location header - won't work.
Dynamically generated downloads - the downloaded file itself will be broken.
etc.
Sorry, but you'll have to give up on BOM and figure another way to handle your locale-specific data (which I can only assume is using another charset for whatever reason).

firefox destroy fonts after a form submission

Currently I am developing a web site by php in Persian ( Farsi language ).The problem is when I submit a form in firefox all fonts get destroyed. like below pictures:
I have checked the code ( include meta tags and others thousands of times ) and it makes it more wierd that this happend only on firefox and no other browser after submission.Is there any bug related to firefox or am I supposed to change any attribute of form .
I am quiet desperated . please help me if anyone has a clue.
One detail of your screenshot caught my attention:
This looks a bit like a LTR variant of UTF-8 BOM.
To quote from Wikipedia Byte Order Mark:
A text editor or web browser interpreting the text as ISO-8859-1 or CP1252 will display the characters "" for this.
I would therefore assume you inject invalid text-fragments having such a BOM inside and existing HTML document (AJAX?), your Firefox browser detects that the document can't be valid Unicode any longer and therefore falls back to ISO-8859-1 which once was the default character encoding for all text documents on the internet.
As the CSS rules still apply, the LTR display was preserved, just the text-encoding meta-information was changed.
Please take care: Having the correct headers is one thing to signal the correct encoding, however it does not unburdened you from actually provide correctly encoded text-data.
I must admit, those BOMs can be pretty tricky, so they are easy to overlook.
Solution: Do not inject any BOM here. If you provide back HTML from a PHP file, check the PHP file that it doesn't use any BOMs.
I figured this issue out.
I used <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />.
I replaced it with UTF8 header in PHP :
header('Content-Type: text/html; charset=utf-8');
and problem solved.
I had another problem that solved with this change.My website pages loaded twice in firefox and its solved now.It seams that fire fox dont like that meta tag at all ;)

Utf8 in html correct and php html output messed up

This issue is mind-boggling to me. I am facing the following situation. I wrote a website in html using the utf8 charset. Special characters are displayed as expected. Now I want to give out some php mysql results, so the easiest way is to create a php file, include the html code and then give out the results. However the html given out via the php file does not display the special characters correctly... it's not utf8
here is the html version: HTML
and here the exact copy in a php file: HTML VIA PHP
To close this question myself (because I feel rather stupid right now), the one who actually solved this is Marc B as his comments made me understand the process of text encoding.
After setting the header (Content Type and charset) as well as setting the meta tag in HTML I discovered, just like Marc suspected that my IDE had encoded the php file in another encoding than UTF8. Saving the file as UTF8 and replacing the messed up specialchars fixed my issue.
Please excuse this, I wasn't fully aware of what I was doing.

Arabic Language Encoding Problem in PHP and ODBC(Sybase)

I am a PHP Developer and Recently I develop a web site using PHP and I connect to a Syabse Database using ODBC.
My database connection is ok and I can display the data in my web pages but I face a problem when arabic data is displayed as it is viewed as squares and not understanding symbols.
I can not change the Database language encoding and it is correct as some other arabic data is displayed well.
I tried the same configuration used in that web page but it does not work too.
I read many realted problems and I tried some solutions and I read about UTF-8, ISO, Windows and Unicode langauge Encodings and I tried to change the HTML Meta tag to display the arabic words but the problem is not solved.
I think my PHP file language Encoding itself may have a problem.
Can I change the PHP file language Encoding ? How to do that if it is possible ?
Is there any solution to dispaly Arabic coming from Database well in PHP web pages ? It is a boring problem :(
I will appreciate any hint or suggestion to solve that problem but please mention your reference and put and example if it is available.
Thanks in Advance...
Just changing the Meta tag isn't enough.
Assuming you want to change your environment to UTF-8, you need to make sure that the following is UTF-8 encoded:
The database tables
The database connection.
The page's encoding (in the Meta tag, or preferably the content-type header)
the PHP file's encoding is irrelevant, unless it contains non-ASCII content itself. In that case, you need to adjust its encoding as well, usually in your IDE's "Save as" dialog.

Getting funny squares in browser when displaying content

I have content stored in a Postgres DB, now everytime I call the content so that it gets displayed using php, i get funny squares in IE and funny square type question marks in Firefox?
Example below
* - March � May 2009
How do I remove this?
I do not have access to the server so can't adjust the encoding there, only have postgres DB details and FTP access to upload my files
I would also recommend: The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!) by Joel Spolsky, I've read it only recently myself, it will definitely help you sort out your problems.
You need to make sure that Postgres, PHP, and your browser all agree on the content encoding, and that you have an appropriate font selected in your browser. The simplest way to do that is to choose UTF8 for everything.
I don't know about PHP, but I do know about databases and browsers. First you need to find out if the database is UTF8. (From psql, I would do a "\l" and look at the encoding.) Then you need to find out if PHP supports UTF8 (I have no idea how you do that). Then you need to see if how those characters are being stored in the database by the PHP app. Then you need to figure out if the web server is correctly reporting the content encoding. (On Linux/Unix, I'd use the program "HEAD" (not "head") to see the headers its returning.) And then you need to figure out if your browser is using a font that supports UTF8.
Or, you could just make sure you only store ASCII and forget the rest of the world exists. Not recommended.
Wrong charset somewhere. The characters could be stored wrong already in database, or you have wrong charset in meta tags on the page(try manually change charset in browser), or there could be problem with wrong encoding when page is communicating with database.
Check this page http://www.postgresql.org/docs/8.2/static/multibyte.html for more informations.
Try to have same encoding on all places, preferably UTF-8
You have encoding issues. Make sure the encoding is set right in the database, in the html markup and make sure the files themselves are saved in proper encoding.

Categories