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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.