3

I have some URL which is in CP-1251 i believe. For example:

http://domain.com/Test - суть в этом.mp3

mb_detect_encoding says it is ASCII. However, I've tried to convert this to UTF-8, but no luck. However the following worked:

$url = mb_convert_encoding(urldecode($url), "Windows-1251", "auto");

Which means that it converted the url to Windows-1251. Which is strange, but it shows the characters right. But when I insert this converted url inside an html object (some music player) it doesn't work. Firebug shows an error:

"NetworkError: 404 Not Found - http://domain.com/Test%20-%20????%20?%20????.mp3"

So somehow I got question marks instead of a right url. urlencode doesn't help.

The file itself is utf-8.

I'm confused with all this stuff. Is there any solution here?

6
  • Have you tried utf8_encode($url)? If your page has it's encoding set to utf-8, this should work. Commented Nov 10, 2011 at 19:58
  • @Michel Mior - yes I have. And it gives me the following: http://domain.com/Test - СÐСÑСâСРРРСÐСâÐ ÑÐ Ñ.mp3 which isn't good of course. Commented Nov 10, 2011 at 20:03
  • When you say "the file itself is utf-8" do you mean the HTML page? Commented Nov 10, 2011 at 20:48
  • 1
    Yes. It doesn't matter now, the problem is solved. Thanks for everybody here for your replies. Commented Nov 10, 2011 at 21:57
  • 1
    Could you post your solution as an answer for future readers? Commented Nov 10, 2011 at 21:58

2 Answers 2

1

Not exactly sure what answer you're looking for but its original encoding is Windows-1251, you can check with iconv:

var_dump(detect_encoding($url);

function detect_encoding($string) { 
  static $list = array('utf-8', 'windows-1251');

  foreach ($list as $item) {
    $sample = iconv($item, $item, $string);
    if (md5($sample) == md5($string))
      return $item;
  }
  return null;
}

This site can also be quite helpful: Universal Cyrillic Decoder

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

Comments

1

Solved.

Just needed to take the file name separately and rawurlencode it.

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.