I am making a script that uses the youtube api to search through videos and store details about some of them in a database. I use javascript to get the data and then store it in a mysql database by using php.
It works fine most of the time but some characters seem to cause syntax error when I assign the data to a javascript array at this line:
var videoList = <?=$videoList; ?>;
It is specifically when I assign it and not when I use it, I have tried resetting the array right after it is assigned and it still causes the error.
One of the strings I found that appears to have caused the error is this one: (I know this line caused the problem before because it started working when I manually deleted it)
Hoppas ni mÃ¥r jätte bra idag â¤ï¸undrar om ni vill att jag ska göra en annan video sÃ¥ fÃ¥r ni jätte Järna kommentera deâ
I use "utf8mb4_unicode_520_ci" in the database and charset="UTF-8" on my website. I am not sure if it is because of charset or some character it can't handle, maybe I need to convert the characters with some function.
Any idea how I can fix it?
Update:
I did like Dan Miller suggested and it didn't work at all.
I also tried what Adrianopolis suggested. I changed the collation of the table and column and already had the charset set in the header. It still cause the problem after changing collation.
var videoList = "<?=$videoList; ?>";var videoList = <?=json_encode($videoList); ?>;return json_encode($return_arr);