简体   繁体   中英

problems with encoding (php)

My site have a utf-8 encoding (Drupal).

I use include function to integrate my page with 3rd party service. But this gives a bad result - bad encoding for include part of page.

i try this, but this don't give any result:

iconv("ASCII","utf-8",include("http://new.velo-travel.ru/themes/themex/spectrum_view.php?$QUERY_STRING"))

before this i use mb_detect_encoding to know encoding

this is included file :

$url = 'http://young.spectrum.ru/cgi-bin/programs_form.pl';
$params = $_GET;
if ($params){
  $url .= '?';
  foreach ($params as $key => $value) $url .= '&' . $keys . '=' . urlencode($value);
}

#$content = file_get_contents($url);
echo iconv("cp-1251","utf-8", $url);

The include function doesn't return a string (unless you actually call return in the included file), it literally includes the content to your source code. So if the server returns PHP source code, it would be interpreted on your server (which basically means the owners of "new.velo-travel.ru" would have control over your site :)).

Also, as Augenfeind pointed out, the page is in windows-1251. So, you probably want:

echo iconv("windows-1251", "utf-8", file_get_contents("http://new.velo-travel.ru/themes/themex/spectrum_view.php?$QUERY_STRING"))

Well, the page you are including is delivered as "windows-1251" by the web server of velo-travel.ru.

So you might want to change the encoding in your iconv-command?!

Try mb_convert_encoding or iconv for all outputted text and literals in your file. For example:

$text = mb_convert_encoding( $oldText, 'UTF-8', "ISO-8859-1" );

or

 $text = iconv( "ISO-8859-1", "UTF-8", $oldText);

Hope you get it working!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM