0

Im trying to change the encoding of a php file (through another php page) to UTF-8 , i mean without editor .

i tried to use file_get_contents and file_put_contents .

i used this code but it doesn't work !

$text = file_get_contents('testencoding.php');
$text = mb_convert_encoding($text, "UTF-8");
file_put_contents('testencoding.php',$text);

this code above is working only if there is a "arabic" characters in the page.

Thanks,

2
  • 1
    And in other cases - what it does? Define doesn't work. And why don't you specify the from_encoding if you know it? Commented Aug 23, 2011 at 1:12
  • Im sorry im not good with english, I dont know the from_encoding because im making a website to convert the encoding from any encoding to UTF-8, i tried to use mb_detect_encoding but it returns bool(false) .. Thanks. Commented Aug 23, 2011 at 14:39

2 Answers 2

2

You must specify from_encoding for the mb_convert_encoding function.

If from_encoding is not specified, it'll use the internal encoding.

Sign up to request clarification or add additional context in comments.

3 Comments

what is the default from_encoding ? is it ansi ? or what ?
Default from_encoding is the internal encoding.
@Programmer4me - You can get the internal encoding by looking at mb_internal_encoding().
0

Try:

$text = file_get_contents('testencoding.php');
file_put_contents('testencoding.php',utf8_encode($text));

if it doesn't work, try:

$text = file_get_contents('testencoding.php');
file_put_contents('testencoding.php',utf8_decode($text));

PS: consider marking the answer as correct if it works, tks :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.