2014-09-08 3 views
1

테이블에서 내 제품의 이름을 가져오고 싶습니다.구문 분석 창문 - 1251 - utf - 8. 텍스트를 잡을 수 없다

하지만 키릴 문자로 이름을 붙잡을 수는 없습니다.

구문 분석을 위해 ganon을 사용하고 있습니다.

이름을 사용하여 배열을 출력하려고하면 키릴 문자를 포함해야하는 모든 값이 비어 있습니다. 왜?

제발 도와주세요. 이미 인코딩을 알고 있기 때문에

$url = "http://www.plati.ru/asp/block_goods_s.asp?id_r=0&id_s=252900&sort=name&page=1&rows=10&curr=EUR&lang=ru-RU&rnd=1544554"; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/7.0"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, false); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50); 
    $result = curl_exec($ch); 
    $redir = curl_getinfo($ch, CURLINFO_HEADER_OUT); 
    curl_close($ch); 

    $html = str_get_dom($result); 

    foreach ($html('.link_good_tab') as $element) { 
     $temp = str_replace("\xA0", ' ', $element->getPlainText()); 
     $products[] = iconv(mb_detect_encoding($temp, mb_detect_order(), true), "UTF-8", $temp); 
    } 
    echo "<pre>"; 
    print_r($products); 
    echo "</pre>"; 

이 결과

[0] => 
    [1] => 
    [2] => 
    [3] => 
    [4] => 
    [5] => 
    [6] => 
    [7] => 
    [8] => 
    [9] => 
    [10] => C&C: Red Alert 3 - Uprising (Origin/RegFree/Multilang) 
+0

이미 알고있는'mb_detect_encoding'과 인코딩을 사용하지 마십시오. – sectus

답변

0

, 그냥 자신을 대신를 설정하고 당신은 또한 mb_convert_encoding()을 사용할 수 있습니다. 예 : 내 컴퓨터에서

$ch = curl_init('http://www.plati.ru/asp/block_goods_s.asp?id_r=0&id_s=252900&sort=name&page=1&rows=10&curr=EUR&lang=ru-RU&rnd=1544554'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($ch); 

$html = str_get_dom($result); 
foreach ($html('.link_good_tab') as $element) { 
    $temp = str_replace("\xA0", ' ', $element->getPlainText()); 
    $products[] = mb_convert_encoding($temp, "utf-8", "windows-1251"); 
} 
echo "<pre>"; 
print_r($products); 
echo "</pre>"; 
0

, mb_detect_order() 반환이 : 시스템의

array (
    0 => 'ASCII', 
    1 => 'UTF-8', 
) 

출력이 가능 비슷한 (즉, 모든-1251 윈도우가 포함되어 있지 않습니다).

인코딩을 자동으로 감지해야하는 이유가 무엇인지 확실하게 알았지 만 필요하다면 원격 서버에서 반환 한 Content-Type 헤더 또는 해당하는 <meta> 태그를 사용해야합니다.

관련 문제