Hi, I have a strange issue, i have a txt file on the server with the following text in: I am using the following to read the document: $file = $_SERVER['DOCUMENT_ROOT'].'/uploads/documents/test.txt'; $contents = file($file); $string = implode($contents); print $string; PHP: But i am getting the below strange characters when i read and print what is in the file. Any ideas why this is happening? Cheers, Adam
When you create that file, insure that you save as UTF-8. It is probably the quotes you have (copied over from a website, office, open office, etc..) If you are saving the file directly from your website, then insure that the PHP script files are UTF-8 as well, it should solve the problem.
Thanks for the replies, how do i save a txt file with encoding? I did not think this was possible? I have tried adding header('Content-Type: text/html; charset=utf-8'); to the page where the text file is read and entered into the database however when the file is echoed it works fine but when entered into the database i still have all the strange characters.
$ f i l e = $ _ S E R V E R [ ' D O C U M E N T _ R O O T ' ] . ' / u p l o a d s / d o c u m e n t s / t e s t . t x t ' ; $ c o n t e n t s = f i l e_get_contents ( $ f i l e ) ; $replace=preg_replace("*'*","\'",$contents); echo nl2br( $replace);
Before adding the insert query, run this query: mysql_query("SET NAMES utf8"); Make sure that the fields also have UTF8 encoding to them (as well as the table).