0

Using getID3, sometimes the tags have special characters in (the little black diamond with the question mark) but I can't seem to remove them

I tried everything from here

PHP: How to remove all non printable characters in a string?

In the database (phpMyAdmin) and when printed out they show up as ?? at the start of the data.

The problem is, I don't want these characters in the database at all (whether they show up properly or show up as question marks)

However, none of the code I've tried will remove these special characters in PHP

cantsay
  • 1,967
  • 3
  • 21
  • 34
  • If you have characters showing up as ?? then you messed something up somewhere. – Dharman Jun 17 '19 at 21:20
  • well getID3 is reading these 2 characters at the beginning of`['id3v2']['TALB'][0]['data']` every time. I assume the ?? are because of encoding type, but the 2 characters shouldn't be there in the first place – cantsay Jun 17 '19 at 21:24

1 Answers1

0

If you're seeing that then you're using the wrong encoding which you haven't shared. The encoding needed is based on the character set in your database.

For example, in MySQL run SHOW CHARACTER SET FOR mydatabase; first, then also SHOW CHARACTER SET FOR mydatabase.mytable; for the table you are accessing data from to get the proper character set.

You can then set the proper encoding.

EternalHour
  • 8,308
  • 6
  • 38
  • 57
  • the DB is `utf8mb4_general_ci` and each table is `latin1_swedish_ci`. the special characters show up when using `print_r` on getid3 info, or echoing certain values. the problem isn't how they're displayed in the database, the problem is I don't want these characters (2 blank spaces) in the database at all. – cantsay Jun 17 '19 at 21:39
  • @cantsay It's an ugly road to remove any special characters you don't want, better to encode it properly before storing. https://stackoverflow.com/questions/910793/detect-encoding-and-make-everything-utf-8 – EternalHour Jun 17 '19 at 21:48
  • Try to set both table and column collation to `utf8mb4_general_ci`, and then when you connect to you MySQL database you also have to instruct the DB server to communicate using UTF-8 ([see this answer](https://stackoverflow.com/a/14068747/1050554)]. – Luxian Jun 17 '19 at 21:51