Jump to content

Help with get_file_content


Evify

Recommended Posts

Hi everyone

 

I'm having some trouble with some charsets when using get_file_content function.

 

I made the followin PHP code:

<?php 
	$file = file_get_contents('omfirma.txt');
	$unescape = array('?','?','?','?','?','?');
	$escape = array('Æ','æ','Ø','ø','Å','å');
	$content = str_replace($unescape, $escape, $file);
	echo $content;
	?>

 

But when i run it the special chars it was supposed to change to HTML entities are displayed as black squares with a ? inside of it. Can you please help me and show me where im doing it wrong? :)

Link to comment
Share on other sites

This hasn't got anything to do with file_get_contents (), but decoding HTML entities. For that, you'll want to use htmlspecialchars_decode ().

 

Also make sure that you've set the correct charset, and that all instances are using the same charset. I recommend using UTF-8, as it's the most compatible.

Link to comment
Share on other sites

I tried this:

 

$file = file_get_contents('omfirma.txt');
	$content = htmlspecialchars_decode($file);
	echo $content;

 

But it still doesn't work. My special chars are still shown as squares with questionmarks in them.

Link to comment
Share on other sites

That hints towards trying to decode something as UTF-8, while it's encoded in a different charset.

Exactly where this error occurs I cannot tell you, because I don't have enough information to determine that. So you'll need to go through every step along the way, and make sure that you're using the same charset every step of the way. If that isn't possible, then you'll need to convert to the correct one at the earliest possible time.

 

For more information on how to do this, please see the PHP manual for Multi Byte string functions.

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.