2017-08-23 20 views
1

我在php中使用curl從網站獲取數據並添加到我的mysql數據庫中。 但我得到的字符串格式奇怪。我嘗試了一些方法,但沒有幫助我。誰曾經處理它,請給我你的解決方案。當使用curl時會得到奇怪的字符php

我的捲髮方法在這裏:

function grab_page($site){ 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); 
curl_setopt($ch, CURLOPT_TIMEOUT, 40); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); 
curl_setopt($ch, CURLOPT_URL, $site); 
ob_start(); 
return curl_exec($ch); 
ob_end_clean(); 
curl_close ($ch); 

}

得到它後,我呼應HTML,我的方法在這裏:

function getDetailPage(){ 
    $detailData = grab_page("https://www.deliverynow.vn/ho-chi-minh/hanuri-quan-an-han-quoc-xo-viet-nghe-tinh"); 
    echo htmlspecialchars($detailData); 
} 

HTML字符串,我得到的是變化怪異字符如:Món khác。但它應該是這樣的:中號óňKH áÇ

回答