Answer the question
In order to leave comments, you need to log in
How to deal with php encoding?
Greetings!
Can you please tell me how to fix the encoding of the received text?
On request
$content = file_get_contents('http://vk.com/foaf.php?id=1');
<foaf:name></foaf:name>
<?
$content = file_get_contents('http://vk.com/foaf.php?id=1');
preg_match_all('#<foaf:name>(.+?)</foaf:name>#is', $content, $arr);
print_r($arr[1]);
?>
<?
$content = file_get_contents('http://vk.com/foaf.php?id=529113');
$pos = strpos($content, '<foaf:name>');
$content = substr($content, $pos);
$pos = strpos($content, '</foaf:name>');
$content = substr($content, 0, $pos);
$content = str_replace('текст который нужно вырезать','', $content);
//$content = iconv("utf-8","windows-1251",$content); //Смена кодировки
print $content;
?>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">.
, indicated in the code<?header("Content-type:text/html; charset=windows-1251");?>
. Changed the encoding of the file itself. In the code I tried to change the encoding with the capabilities of php itself$content1 = iconv("utf-8","windows-1251",$content); //Смена кодировки
AddDefaultCharset windows-1251
and PHP_VALUE default_charset windows-1251
Answer the question
In order to leave comments, you need to log in
$content = iconv("windows-1251", "utf-8",$content); //Смена кодировки
string iconv ( string in_charset, string out_charset, string str )
Converts the character encoding of the string str from the initial encoding of in_charset to the final encoding of out_charset. Returns the string in the new encoding, or FALSE on error.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question