2011-03-25 38 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