2011-03-25 66 views
1

如何走到这一步的工作

copy("http://translate.google.com/translate_tts?tl=en&q=Love+Me", "/directory/loveme.mp3"); 

但是,这不?

copy("http://translate.google.com/translate_tts?tl=hi&q=%26%232310%3B%26%232354%3B%26%232370%3B+%26%232327%3B%26%232379%3B%26%232349%3B%26%232368%3B", "/directory/loveme.mp3"); 

如果我将两个URL都粘贴到浏览器中,它们都可以正常播放。但第二个URL只是复制一个空白的mp3文件,而第一个复制正确的MP3文件。

回答

0

尝试调用copy之前在URL这样:

function utf8RawUrlDecode ($source) { 
    $decodedStr = ""; 
    $pos = 0; 
    $len = strlen ($source); 
    while ($pos < $len) { 
     $charAt = substr ($source, $pos, 1); 
     if ($charAt == '%') { 
      $pos++; 
      $charAt = substr ($source, $pos, 1); 
      if ($charAt == 'u') { 
       // we got a unicode character 
       $pos++; 
       $unicodeHexVal = substr ($source, $pos, 4); 
       $unicode = hexdec ($unicodeHexVal); 
       $entity = "&#". $unicode . ';'; 
       $decodedStr .= utf8_encode ($entity); 
       $pos += 4; 
      } 
      else { 
       // we have an escaped ascii character 
       $hexVal = substr ($source, $pos, 2); 
       $decodedStr .= chr (hexdec ($hexVal)); 
       $pos += 2; 
      } 
     } else { 
      $decodedStr .= $charAt; 
      $pos++; 
     } 
    } 
    return $decodedStr; 
} 

我在docs for rawurldecode得到这个从意见 - 的方式向下滚动。

+0

我试过这个,但它仍然没有工作。 – mellowg 2011-03-26 01:19:01