![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 247 Pomógł: 5 Dołączył: 10.12.2007 Ostrzeżenie: (0%) ![]() ![]() |
Witam
Mam kod:
I po wyświetleniu go na stronę zauważyłem, że literka ó nie jest poprawnie kodowana. Plik jest kodowany w utf-8. Jak można naprawić ten błąd? mb_check_encoding zwraca true Zauważyłem, że trzeba dopsiać str_replace('& o a c u t e ;','\u00f3',$data); Spacje dodane specjalnie Tylko dlaczego json_encode tego nie robi? ![]() Klasa remote.php Kod <?php
/** * Provides remote server communications options using [curl](http://php.net/curl). * * @package Kohana * @category Helpers * @author Kohana Team * @copyright (c) 2008-2010 Kohana Team * @license http://kohanaframework.org/license */ class Remote { /** * @var array default cURL options */ public static $default_options = array ( CURLOPT_USERAGENT => 'Mozilla/5.0 (compatible; Kohana v3.0 +http://kohanaframework.org/)', CURLOPT_CONNECTTIMEOUT => 8, CURLOPT_TIMEOUT => 12, ); /** * Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt) * may be used. * * // Do a simple GET request * $data = Remote::get($url); * * // Do a POST request * $data = Remote::get($url, array( * CURLOPT_POST => TRUE, * CURLOPT_POSTFIELDS => http_build_query($array), * )); * * @param string remote URL * @param array curl options * @return string * @throws Kohana_Exception */ public static function get($url, array $options = NULL) { if ($options === NULL) { // Use default options $options = Remote::$default_options; } else { // Add default options $options = $options + Remote::$default_options; } // The transfer must always be returned $options[CURLOPT_RETURNTRANSFER] = TRUE; // Open a new remote connection $remote = curl_init($url); // Set connection options if ( ! curl_setopt_array($remote, $options)) { throw new Exception('Failed to set CURL options, check CURL documentation: http://php.net/curl_setopt_array'); } // Get the response $response = curl_exec($remote); // Get the response information $code = curl_getinfo($remote, CURLINFO_HTTP_CODE); if ($code AND $code < 200 OR $code > 299) { $error = $response; } elseif ($response === FALSE) { $error = curl_error($remote); } // Close the connection curl_close($remote); if (isset($error)) { throw new Exception('Error fetching remote '.$url.' [ status '.$code.' ] '.$error); } return $response; } /** * Returns the status code (200, 500, etc) for a URL. * * $status = Remote::status($url); * * @param string URL to check * @return integer */ public static function status($url) { // Get the hostname and path $url = parse_url($url); if (empty($url['path'])) { // Request the root document $url['path'] = '/'; } // Open a remote connection $port = isset($url['port']) ? $url['port'] : 80; $remote = fsockopen($url['host'], $port, $errno, $errstr, 5); if ( ! is_resource($remote)) return FALSE; // Set CRLF $line_feed = "\r\n"; // Send request fwrite($remote, 'HEAD '.$url['path'].' HTTP/1.0'.$line_feed); fwrite($remote, 'Host: '.$url['host'].$line_feed); fwrite($remote, 'Connection: close'.$line_feed); fwrite($remote, 'User-Agent: Kohana Framework (+http://kohanaframework.org/)'.$line_feed); // Send one more CRLF to terminate the headers fwrite($remote, $line_feed); // Remote is offline $response = FALSE; while ( ! feof($remote)) { // Get the line $line = trim(fgets($remote, 512)); if ($line !== '' AND preg_match('#^HTTP/1\.[01] (\d{3})#', $line, $matches)) { // Response code found $response = (int) $matches[1]; break; } } // Close the connection fclose($remote); return $response; } } // End remote Ten post edytował mimol 16.02.2013, 18:17:40 |
|
|
![]()
Post
#2
|
|
Grupa: Zarejestrowani Postów: 61 Pomógł: 4 Dołączył: 18.09.2010 Ostrzeżenie: (0%) ![]() ![]() |
Plik masz w utf ale to co pobierasz jest pewnie w innym kodowaniu. Użyj funkcji iconv.
Ten post edytował Inscure 18.02.2013, 11:57:27 -------------------- eXtreme-Fusion CMS - polski, darmowy system zarządzania treścią z rozbudowanym wsparciem technicznym.
|
|
|
![]()
Post
#3
|
|
![]() Grupa: Zarejestrowani Postów: 6 476 Pomógł: 1306 Dołączył: 6.08.2006 Skąd: Kraków Ostrzeżenie: (0%) ![]() ![]() |
Najzwyczajniej w świecie Filmweb w źródle swoich stron, literę "ó" zapisuje jako HTML-owską encję z bliżej nieznanego mi powodu.
|
|
|
![]()
Post
#4
|
|
Grupa: Zarejestrowani Postów: 247 Pomógł: 5 Dołączył: 10.12.2007 Ostrzeżenie: (0%) ![]() ![]() |
mb_check_encoding zwraca true jeśli testuje pod UTF-8, wydaje mi się, że to co pobieram jest w UTF-8 (takie kodowanie jest ustawione w nagłówku)
iconv() co podać jako pierwszy parametr?. iconv('UTF-8', 'UTF-8',$data); nie działa (logiczne) |
|
|
![]()
Post
#5
|
|
![]() Grupa: Zarejestrowani Postów: 387 Pomógł: 66 Dołączył: 31.03.2005 Skąd: Kielce Ostrzeżenie: (0%) ![]() ![]() |
Najzwyczajniej w świecie Filmweb w źródle swoich stron, literę "ó" zapisuje jako HTML-owską encję z bliżej nieznanego mi powodu. Normalnie rozwalili mnie, bo masz rację ![]() Kod podróż Do tego większość wyrazów posiada polskie znaki ale samo ó zamieniane jest na o : Jakby nie było ich stać na dobrych developerów ![]() -------------------- ..::: Jak pomogłem to kliknij pomógł. Tak rzadko używacie tej opcji :( :::..
|
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 24.07.2025 - 16:33 |