Мне нужно получить содержимое персидской страницы и показать часть этой страницы некоторым пользователям. Проблема в том, что после фильтрации содержимого страницы я не могу отобразить содержимое в правильной кодировке. Веб-страница расположена по адресу sena.ir, и вот снимок экрана исходной части веб-страницы, которую я хочу показать:
замещающий текст http://img502.imageshack.us /img502/983/original.gif
И вот что у меня получилось:
alt text http:/ /www.freeimagehosting.net/uploads/812cebe6b3.gif
Вот функция, которую я использую для получения содержимого страницы:
function getPage($url, $referer="", $timeout="", $header=""){
if(!isset($timeout))
$timeout=30;
$curl = curl_init();
if(strstr($referer,"://")){
curl_setopt ($curl, CURLOPT_REFERER, $referer);
}
$headers [] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
$headers [] = 'Connection: Keep-Alive';
$headers [] = 'Content-type: application/x-www-form-urlencoded;charset=utf-8 '; // I Tried iso-..... as well but no chance
$user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$compression = "gzip";
curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers );
curl_setopt ($curl, CURLOPT_HEADER, 0 );
curl_setopt ($curl, CURLOPT_USERAGENT, $user_agent );
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1 );
curl_setopt ($curl, CURLOPT_POST, 0 );
curl_setopt ($curl, CURLOPT_ENCODING, $compression );
curl_setopt ($curl, CURLOPT_TIMEOUT, 300 );
curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt ($curl, CURLOPT_URL, $url);
$html = curl_exec ($curl);
curl_close ($curl);
return $html;
}
$content = getPage("http://sena.ir/");
$p1 = strpos($content,'');
$p2 = strpos($content,"",$p1);
$content = substr($content, $p1, $p2-$p1);
echo $content;
Подробнее здесь: https://stackoverflow.com/questions/182 ... -using-php
Невозможно отобразить загруженную веб-страницу с правильной кодировкой с помощью PHP. ⇐ Php
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Невозможно отобразить загруженную веб-страницу с правильной кодировкой с помощью PHP.
Anonymous » » в форуме Php - 0 Ответы
- 12 Просмотры
-
Последнее сообщение Anonymous
-