Jump to content

[SOLVED] strange characters � from fread()


countdrac

Recommended Posts

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

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

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

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.