tags:

views:

63

answers:

2

i have a txt file with a list of country's. For my form i just read all the data in a select list line per line with fgets(). And that works fine except for some problems.

1) When i have a country with ¨ on a letter it comes in the list just as a blank. 2) When i put the data in an xml at the end it seams there is a return at the end of each value in the form of '&#xD'.

so my question. Is there either a way to fix these problems or is there a better way to read data from a file. Or should i use on other filetype then txt?

+1  A: 

It sounds like a trouble with the text encoding. You could try to run htmlentities on the text before echo:ing it out. Another solution is to use utf8_encode or utf8_decode (depending on which encoding your pages are served as, and on the encoding of the file).

Emil Vikström
the utf8 solves the first problem. But the return is still there.using htmlentities() messes it up completely,
Dazz
@unknown(google) htmlentities has a default charset ISO-8859-1, you may chnage that to utf8 if you are using it.
joetsuihk
Dazz
ë is an HTML entity that is used to work around text encoding issues in web pages. You can skip htmlentities if it's not giving you the desired effect.
Emil Vikström
then there still is the return that doest go away.My source looks like this:<option value="Albanie">Albanie</option><option value="Andorra">Andorra</option><option value="Bosnië">Bosnië</option><option value="Bulgarije">Bulgarije</option>
Dazz
I don't know what "return" you are talking about. Do you mean a newline?
Emil Vikström
A: 

In character data, the carriage-return (#xD) character is represented by &#xD;

Just make sure that after you've read each line, you str_replace('\r', '', $line) each line to remove the carriage-return character from the end of the line.

Blair McMillan
You could also use the `trim` function, which takes care of any whitespace, not just `\r`.
Samir Talwar