Ste*_*gin 2 mysql bash curl utf-8 character-encoding
我想将使用curl获得的任何网站的输出转换为数据插入的utf8.
用法ex:
html="$(curl -iL -compressed "$link")"
##code needed to convert nonUTF8 $html to utf8, preferably without writing to file
## escape characters for insert
html_q="${html//'\'/\\\\}"
html_q="${html_q//"'"/\'}"
## the insert statement
sqlHtml='INSERT INTO `'"${tableHtml}"'` (`html`) VALUES ('"'${html_q}'"');'
mysql -u$dbUser -p$dbPass -h$dbHost -P$dbPort -D$dbName --default_character_set utf8 -A <<ENDofMESSAGE
${sqlHtml}
ENDofMESSAGE
Run Code Online (Sandbox Code Playgroud)
简短的问题,简短的回答:
man iconv
现在,您还有一个问题:确定网页的源代码编码.(提示:在谷歌中键入charsetdetector)