countdrac Posted November 7, 2007 Share Posted November 7, 2007 hi for some reason when i use "include" for displaying a file in my page everythings perfect but now im using ajax so the "displayFile.php" which is where i use fread for an entire file and save it into a variable and send back to the javascript function to display has some of the characters - mostly singe quotes ' appearing as � is there a way to fix this? is this a problem with my file or fread? the code for the fread is... $fileName = $_GET["q"]; $file=fopen($fileName,"r"); $result = fread($file, filesize($fileName)); fclose($file); echo $result; then the javscript where its sent to... if (xmlHttp.readyState==4) { document.getElementById('displayDoc').innerHTML = xmlHttp.responseText; } thanks Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 you should use file_get_contents instead of fread If I am not mistaken fread print directly to the output buffer not sure tho Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 you should use file_get_contents instead of fread If I am not mistaken fread print directly to the output buffer not sure tho file_get_contents is only in php4.3 or greater, but that isn't the issue. its whitespace in the file being opened Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 yeah its binary safe fread sorry for the confusion Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 7, 2007 Author Share Posted November 7, 2007 hi thanks for the help so i tried first: $result = preg_replace('/\s\s+/',' ',$result); and $result = preg_replace(' ',' ',$result); which just crashed and returns nothing then i tried string replace which even when i tried $result = str_replace(' ',' ',$result); which as a function works and does what it supposed to... but doesnt get rid of the � characters... besides all that like i said i think that they are certain: single quotations, double quotations and dashes in the file im still kinda new to php so any help would be helpful... what do you recommend the best way to to fix this is? thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted November 7, 2007 Share Posted November 7, 2007 You may need to display this in UTF-8: <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 7, 2007 Author Share Posted November 7, 2007 ye i tried to stick that in the header... didnt help Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 lets try and nullify them instead of removing them. Try and isolate their location in the included file and remove them. Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 7, 2007 Author Share Posted November 7, 2007 do you mean physically go into the included file? i have like 50 files... how do i isolate what that � is? ive been trying but i cant figure out how to do it... Quote Link to comment Share on other sites More sharing options...
effigy Posted November 7, 2007 Share Posted November 7, 2007 Do you know the encoding of the source? I'm guessing it's Windows-1252 because it uses "smart quotes" that err in UTF-8 when they are not converted properly. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2007 Share Posted November 7, 2007 well save it to a file an check it in editplus or textpad you'll know the exact code that is returning you the block Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted November 7, 2007 Share Posted November 7, 2007 my point is if you can isolate one you might learn something about the issue Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 7, 2007 Author Share Posted November 7, 2007 ok cool so i got textpad and it seems they for sure something different... when i highlight the wierd character the code comes up: 0x92, 0x93, 0x94 and 0x97 (depending on which i go over) from a couple of files ive looked at these are the ones that are giving problems..... im not sure if there are others at this point... what are they and how can i isolate them in a string replace (-or whatever) thanks Quote Link to comment Share on other sites More sharing options...
effigy Posted November 7, 2007 Share Posted November 7, 2007 After you've read in the data, you can use iconv to convert from Windows-1252 => UTF-8. Quote Link to comment Share on other sites More sharing options...
countdrac Posted November 7, 2007 Author Share Posted November 7, 2007 Thanks did the job! $result = iconv("WINDOWS-1250","UTF-8",$result); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.