From 0cc6b90e8b6fbabd38c940cb4acec9fc33a80d95 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 3 Sep 2012 09:42:58 +0000 Subject: [PATCH] Add encoding convert --- batch/getKbis.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/batch/getKbis.php b/batch/getKbis.php index fa990a78..116738f9 100644 --- a/batch/getKbis.php +++ b/batch/getKbis.php @@ -57,6 +57,16 @@ if(count($opts->getOptions())==0 || isset($opts->help)) exit; } +function getPageHeader($start,$end,$header) +{ + $pattern = '/'. $start .'(.*?)'. $end .'/'; + if (preg_match($pattern, $header, $result)) { + return $result[1]; + } else { + return false; + } +} + function getPage($url, $curl_data = '', $verbose=false) { global $ckfile; @@ -103,6 +113,10 @@ function getPage($url, $curl_data = '', $verbose=false) $header = curl_getinfo($ch); curl_close($ch); + //Rewrite encoding to UTF-8 + $encoding = getPageHeader('Content-Type: text/html; charset=', '\n', $header); + $content = iconv($encoding, 'UTF-8', $content); + // $header['errno'] = $err; // $header['errmsg'] = $errmsg; // $header['content'] = $content;