Firefox/IE discrepancy with php

Started by fred, Thu 07/09/2006 04:02:15

Previous topic - Next topic

fred

I just recently set up a php script that reads in information from a .txt file to php arrays, does some sorting and displays the data in a html table.

Now, this works fine in IE, but in Mozilla Firefox, some text strings are read in (and displayed) wrong. Some of the strings are displayed correctly, while some have inserted special characters looking like little squares = ⌂Ã,  in between *all* the original characters, making the text very hard to read.

To complicate this furhter, extra linebreaks are inserted in the strings by firefox at random, it seems, and only some of the new lines have the extra special character squares inserted.

If anybody knows what this could be, please give suggestions, I tried a lot of things already but best 'fix' so far is a "Best viewed in Internet Explorer"-comment on the page.Ã,  :P

juncmodule

If I'm not mistaken it isn't really the php you should be looking at. As a server side language it doesn't matter what browser you use. You should look at the source of the rendered page in both browsers. Odds are the actual html that the php page is outputting is not valid and causing issues. Run the page through the w3c validator and find out where the tags are causing problems if you can't see any obvious problems. However, I suspect when you look at the rendered html source the problems will be obvious. Internet Explorer is great for running any garbage you plug into it. So that is why it looks better there. However, "best viewed in" isn't a proper solution. You should at least put some effort into making the page more compliant. Good luck!

later,
-junc

Radiant

Seems to me the text file might be in Unicode (which uses two-byte characters) which is somehow treated as ASCII (which uses one-byte characters). That would explain the little boxes. It's not a Firefox problem, FF can handle Unicode just fine. And Junc is correct in that PHP runs on the server and is thus not affected by the browser used.

fred

Thanks, it makes sense. When I look at the source from IE, it shows up fine, when I look at it in FF, the lines don't wrap - I get one very long line containing all the output for the table - looks very strange, with overlapping words...

w3c invalidates because of char encoding issues, so I'm sure there's a problem with the html header and/or charset I echo from php. Never understood doctypes and character encoding optionsÃ,  :-[ especially not when reading in from txt files to php-generated html.

the url is here if anyone wants to marvel at the madness.

Alynn

Well, I can guess why it's not wrapping. When using echo in php, it doesn't automatically break the line once you close the echo string. so when you iterate your loop and echo again, it just appends it right where the previous echo left off... you can explicitly force it to line break by putting a \n at the end of your echo string (before closing the string or is it /n... gah I forget off the top of my head).

Now, I don't remember exactly, but IIRC using HTML 4.01 transitional, it doesn't like the /> at the end of the meta tag, for xhtml that is correct.

As far as character encoding itself goes, I can't really tell you, I've never messed with anything other than the windows-1252 since frontpage puts it in there automatically (but I use dreamweaver when doing php... mostly because I like the fact that frontpage connects directly to the server, and saves pages faster onto the server than the FTP based dreamweaver)...

Anyway putting your code through the validator... the only issue with your encoding meta is that you have a /> at the end... so remove the slash and you are good there

Most of your other errors are due to using characters that aren't in the character encoding you are using... which is why you are probably getting boxes...

For those special characters you need to http://www.w3.org/MarkUp/html3/utf8.html <-- check that out... it has the codes on how to do all the "special characters" for webpages. I'm guessing this is where your problem lies.


Ishmael

My guess is that the browsers are misunderstanding the charset markup. I don't know much about them myself, but that's the only thing I can think of.

I myself use this:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

Works fine in all browsers. If you've got the same charset I'm clueless.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

fred

Ok, thanks a lot all, I think I found a solution.

The txt files that are read in seem to contain traces from copy and paste actions, showing up as square characters. So every string is now parsed and stripped of non-ascii characters before being echo'ed. Glad I found this function for it, definately wouldn't have come up with it myself:
Code: ags
function clean_string_input($input)
{
Ã,  Ã, $search = array(
Ã,  Ã,  Ã,  Ã, '/[\x60\x82\x91\x92\xb4\xb8]/i',Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // single quotes
Ã,  Ã,  Ã,  Ã, '/[\x84\x93\x94]/i',Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // double quotes
Ã,  Ã,  Ã,  Ã, '/[\x85]/i',Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  // ellipsis ...
Ã,  Ã,  Ã,  Ã, '/[\x00-\x0d\x0b\x0c\x0e-\x1f\x7f-\x9f]/i'Ã,  Ã,  // all other non-ascii
Ã,  Ã, );
Ã,  Ã, $replace = array(
Ã,  Ã,  Ã,  Ã, '\'',
Ã,  Ã,  Ã,  Ã, '"',
Ã,  Ã,  Ã,  Ã, '...',
Ã,  Ã,  Ã,  Ã, ''
Ã,  Ã, );
Ã,  Ã, return preg_replace($search,$replace,$input);
} 


Don't know what gets people into coding like that, but happy something does, as it seems to have fixed my problem.  :)

Esseb

Small tip: You don't need font tags around every single bit of text on that page, nor do you need to specify a background colour for every single cell, but I'll leave it up to you to find a better way to do it.

fred

Thanks Esseb, I know I don't use styles as much as I probably should - guess it will take some time before I remember css tags like i do html. A bit tricky with two different syntaxes for the same elements and attributes. In this case, the cells get their color and font in a loop, so typing was light. ;)

Esseb

I wasn't specifically talking about CSS, even with the olde tyme font tags and bgcolor attribute you don't need one for every cell. Nice to know you're progressing into CSS though.

Alynn

Stylesheets are probably the best thing to ever happen to html. It makes converting your whole site to a different color scheme about 100% easier since you only have to change one file instead of all of them.

There are plenty of CSS tutorials out there so even if you don't know exactly how to do something, a quick search in google and you will find out.

fred

Ok, so I put the font tags 'outside' the table, and gave the whole table a default background color. Thanks for the hints. Haven't uploaded the new file, though - server trouble.

CSS is cool, no doubt.Ã,  Ã, 8)

SMF spam blocked by CleanTalk