Recently doing PHP crawl, php+mssql collocation. Oh. Oh.. Looking for information on the Internet is very few. It seems to be a big upset. Look east. Look at the West. Finally, let me get something to tinker with. (recently there will be a php+mssql of information come out oh:>). Go to the chase.
PHP Crawl is crawling out of it. Crawl news headlines and news content. The first thing to do is to display the captured title and content directly.
The Default_charset key setting in PHP.ini is this: Default_charset = "Utf-8"
But the light capture takes off to deposit the database.
This is a problem.
Here is the join database function
PHP code*******************************************************
function insert_db ($title, $content, $lie)
{
$dsn = ' Driver={sql Server}; Server=127.0.0.1;database=test ';
$link =odbc_connect ($dsn, ' sa ', ' admin ') or die (' Eeeor ');
Odbc_exec ($link, "INSERT INTO News (". $lie. ", content) VALUES ('". $titile. "', '". $content. "')");
Odbc_close ($link);
}
*************************************************************************************************************** **
But to the database a look miserable. It's all garbled. I looked for an article online. Look at the original because of the text encoding problem.
The default is CHINESE_PRC rule encoding ordering in MSSQL. And I set in PHP is UTF-8 so it will be garbled. But I set the php.ini default_charset item to GB2312 crawl to the title and content into MSSQL is also garbled. Depressed. Let's just ignore that.
Since the coding is wrong. Then the unification is not OK ...
Use the following function: Iconv (), encode the specified content and return the encoded content ...
Iconv ("Utf-8", "gb2312", $title); This translates the captured title into MSSQL. Look at the ha. The conversion succeeded. A slip of the Chinese title. Without any garbled characters. Oh. Oh...
Because PHP is UTF-8 so the time to correspond oh ...
Iconv ("gb2312", "Utf-8", $title), so that you can display the normal content on the Web page!!!
It's done!
PHP read/write MSSQL garbled!