Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php mp3字符串错误_Php_Mysql_String_Mp3 - Fatal编程技术网

php mp3字符串错误

php mp3字符串错误,php,mysql,string,mp3,Php,Mysql,String,Mp3,我有一个mp3课程来阅读我网站上的mp3。(我无法安装该模块,因为它是共享主机)。我上传mp3,然后系统使用我的类读取它,并将文件名和位置以及基本标记(艺术家、歌曲名、唱片集)插入mysql。mysql插入是可以的,但是我插入的字符串有问题 这是我的密码: 我的代码有什么问题?根据您的代码,$值需要修剪或转换为UTF(我更喜欢转换为UTF)。 我添加了一个功能,可以检查哪个UTF是mp3并正确解析它: $value = $this->filter($value, $tag); // con

我有一个mp3课程来阅读我网站上的mp3。(我无法安装该模块,因为它是共享主机)。我上传mp3,然后系统使用我的类读取它,并将文件名和位置以及基本标记(艺术家、歌曲名、唱片集)插入mysql。mysql插入是可以的,但是我插入的字符串有问题

这是我的密码:


我的代码有什么问题?

根据您的代码,$值需要修剪或转换为UTF(我更喜欢转换为UTF)。 我添加了一个功能,可以检查哪个UTF是mp3并正确解析它:

$value = $this->filter($value, $tag); // convert to UTF or else that is why you have weird chars
这是一个例子


可能您使用了错误的算法。应该有针对您的问题的现有代码,只需使用一些有效的代码,可能从这里开始:正如我在问题中所说,这些id3不可用,我无法添加它们
Array
(
    [genre] => ��Rock
    [title] => ��Walk
    [artist] => ��Foo Fighters
    [album] => ��Wasting Light
)
$value = $this->filter($value, $tag); // convert to UTF or else that is why you have weird chars
<?php

class Id3 {

  private $tags = array(
    'TALB' => 'album',
    'TCON' => 'genre',
    'TENC' => 'encoder',
    'TIT2' => 'title',
    'TPE1' => 'artist',
    'TPE2' => 'ensemble',
    'TYER' => 'year',
    'TCOM' => 'composer',
    'TCOP' => 'copyright',
    'TRCK' => 'track',
    'WXXX' => 'url',
    'COMM' => 'comment'
  );

  private $genre = array(
    0   => 'Blues',
    1   => 'Classic Rock',
    2   => 'Country',
    3   => 'Dance',
    4   => 'Disco',
    5   => 'Funk',
    6   => 'Grunge',
    7   => 'Hip-Hop',
    8   => 'Jazz',
    9   => 'Metal',
    10  => 'New Age',
    11  => 'Oldies',
    12  => 'Other',
    13  => 'Pop',
    14  => 'R&B',
    15  => 'Rap',
    16  => 'Reggae',
    17  => 'Rock',
    18  => 'Techno',
    19  => 'Industrial',
    20  => 'Alternative',
    21  => 'Ska',
    22  => 'Death Metal',
    23  => 'Pranks',
    24  => 'Soundtrack',
    25  => 'Euro-Techno',
    26  => 'Ambient',
    27  => 'Trip-Hop',
    28  => 'Vocal',
    29  => 'Jazz+Funk',
    30  => 'Fusion',
    31  => 'Trance',
    32  => 'Classical',
    33  => 'Instrumental',
    34  => 'Acid',
    35  => 'House',
    36  => 'Game',
    37  => 'Sound Clip',
    38  => 'Gospel',
    39  => 'Noise',
    40  => 'Alternative Rock',
    41  => 'Bass',
    42  => 'Soul',
    43  => 'Punk',
    44  => 'Space',
    45  => 'Meditative',
    46  => 'Instrumental Pop',
    47  => 'Instrumental Rock',
    48  => 'Ethnic',
    49  => 'Gothic',
    50  => 'Darkwave',
    51  => 'Techno-Industrial',
    52  => 'Electronic',
    53  => 'Pop-Folk',
    54  => 'Eurodance',
    55  => 'Dream',
    56  => 'Southern Rock',
    57  => 'Comedy',
    58  => 'Cult',
    59  => 'Gangsta',
    60  => 'Top 40',
    61  => 'Christian Rap',
    62  => 'Pop/Funk',
    63  => 'Jungle',
    64  => 'Native US',
    65  => 'Cabaret',
    66  => 'New Wave',
    67  => 'Psychadelic',
    68  => 'Rave',
    69  => 'Showtunes',
    70  => 'Trailer',
    71  => 'Lo-Fi',
    72  => 'Tribal',
    73  => 'Acid Punk',
    74  => 'Acid Jazz',
    75  => 'Polka',
    76  => 'Retro',
    77  => 'Musical',
    78  => 'Rock & Roll',
    79  => 'Hard Rock',
    80  => 'Folk',
    81  => 'Folk-Rock',
    82  => 'National Folk',
    83  => 'Swing',
    84  => 'Fast Fusion',
    85  => 'Bebob',
    86  => 'Latin',
    87  => 'Revival',
    88  => 'Celtic',
    89  => 'Bluegrass',
    90  => 'Avantgarde',
    91  => 'Gothic Rock',
    92  => 'Progressive Rock',
    93  => 'Psychedelic Rock',
    94  => 'Symphonic Rock',
    95  => 'Slow Rock',
    96  => 'Big Band',
    97  => 'Chorus',
    98  => 'Easy Listening',
    99  => 'Acoustic',
    100 => 'Humour',
    101 => 'Speech',
    102 => 'Chanson',
    103 => 'Opera',
    104 => 'Chamber Music',
    105 => 'Sonata',
    106 => 'Symphony',
    107 => 'Booty Bass',
    108 => 'Primus',
    109 => 'Porn Groove',
    110 => 'Satire',
    111 => 'Slow Jam',
    112 => 'Club',
    113 => 'Tango',
    114 => 'Samba',
    115 => 'Folklore',
    116 => 'Ballad',
    117 => 'Power Ballad',
    118 => 'Rhytmic Soul',
    119 => 'Freestyle',
    120 => 'Duet',
    121 => 'Punk Rock',
    122 => 'Drum Solo',
    123 => 'Acapella',
    124 => 'Euro-House',
    125 => 'Dance Hall',
    126 => 'Goa',
    127 => 'Drum & Bass',
    128 => 'Club-House',
    129 => 'Hardcore',
    130 => 'Terror',
    131 => 'Indie',
    132 => 'BritPop',
    133 => 'Negerpunk',
    134 => 'Polsk Punk',
    135 => 'Beat',
    136 => 'Christian Gangsta Rap',
    137 => 'Heavy Metal',
    138 => 'Black Metal',
    139 => 'Crossover',
    140 => 'Contemporary Christian',
    141 => 'Christian Rock',
    142 => 'Merengue',
    143 => 'Salsa',
    144 => 'Trash Metal',
    145 => 'Anime',
    146 => 'Jpop',
    147 => 'Synthpop'
  );
  private $file;
  private $info;

  public function __construct() {
    $this->info = array(
      'genre' => 'unknow',
      'title' => 'unknow',
      'artist' => 'unknow',
      'album' => 'unknow',
    );
  }

  private function filter($tag, $type) {
    if ($type == 'COMM') {
      $tag = substr($tag, 0, 3) . substr($tag, 10);
    }
    if(ord($tag[2]) == 0) {
      return iconv('UTF-8', 'ISO-8859-1', substr($tag, 3));
    }
    elseif(ord($tag[2]) == 1) {
      return iconv('UTF-16LE', 'UTF-8', substr($tag, 5));
    }
    elseif(ord($tag[2]) == 2) {
      return iconv('UTF-16BE', 'UTF-8', substr($tag, 5));
    }
    elseif(ord($tag[2]) == 3) {
      return substr($tag, 3);
    }
    return false;
  }

  private function getId3() {
    $handle = fopen($this->file, 'rb');
    $head = fread($handle, 10);
    $head = unpack("a3signature/c1version_major/c1version_minor/c1flags/Nsize", $head);
    if (!$head['signature'] == 'ID3') {
      fclose($handle);
      return false;
    }
    $result = array();
    for ($i = 0; $i < 22; $i++) { //22 most popular tags, you had 5 therefore only the first five.
      $tag = rtrim(fread($handle, 6));
      if (!isset($this->tags[$tag])) {
        continue;
      }
      $size = fread($handle, 2);
      $size = unpack('n', $size);
      $size = $size[1]+2;
      $value = fread($handle, $size);
      $value = $this->filter($value, $tag); // convert to UTF or else that is why you have weird chars
      $this->info[$this->tags[$tag]] = $value;
    }
    fclose($handle);
  }

  public function load($file) {
    $this->file = $file;
    $this->getId3();
  }

  public function getInfo() {
    return $this->info;
  }

}

$id3 = new Id3();
$id3->load('mp3.mp3');
print_R($id3->getInfo());