I have the below string (in Turkish):
$string = "Otpor lideri Maroviç: Gezi eylemcileriyle temasımız olmadı";
However, when I attempt to echo the string, I get the below result:
Otpor lideri Maroviç: Gezi eylemcileriyle temas?m?z olmad?
How can I solve this problem?
First of all:
$string = "Otpor lideri Maroviç: Gezi eylemcileriyle temasımız olmadı";
echo htmlentities($string);
And make sure to add... to your head
<meta charset="UTF-8">
header('Content-type: text/plain; charset=utf-8');
$string = "Otpor lideri Maroviç: Gezi eylemcileriyle temasımız olmadı";
echo $string;
Open your file with code editor ex. Notepad++ and use "Convert to UTF-8" function.
This should help. Here in Poland we are also using special characters and this is a common problem.
Related
I get a city name as a GET variable. I need to make the first letter capitalized.
If the Get variable is "herning" I kan with no problem make it H, but if the Variable is "ølstykke" I can only make it lowercase ø, not uppercase Ø.
header('Content-type: text/html; charset=utf-8');
print strToUpper(mb_substr($_GET["city"], 0, 1));
If I do not set the header to utf-8, I just get strange characters.
Any ideas?
Updated code
<?php
header('Content-type: text/html; charset=utf-8');
$city = mb_convert_case($_GET["city"], MB_CASE_TITLE, "UTF-8");//Ølstykke
print $city;
$section = file_get_contents('https://api.dataforsyningen.dk/steder?hovedtype=Bebyggelse&undertype=by&prim%C3%A6rtnavn='.$city);
$section = json_decode($section);
print '<pre>';
print_r($section);
print '</pre>';
Solution: urlencode() around $city when sending to dataforsyningen did the job.
Use mb_strtoupper and specify the character-encoding in mb_substr
echo mb_strtoupper(mb_substr('ølstykke', 0, 1,'utf-8'));//Ø
In your case maybe you want not only first character but also the rest characters,
so maybe mb_convert_case function can help you.
echo mb_convert_case('ølstykke', MB_CASE_TITLE, "UTF-8");//Ølstykke
I have following line of code,
echo substr('Sergio Agüero',0,10);
And it will display Sergio Ag�
But I want output like "Sergio Agü"
I don't want special character. So is it possible? Any help is really appreciated.
You can do this using mb_internal_encoding and mb_substr.
Example: online test
mb_internal_encoding("UTF-8");
$str = 'Sergio Agüero';
echo mb_substr($str, 0, 10); //Sergio Agü
More about: mb-substr
Use utf8_decode. Try this:
echo substr(utf8_decode("Sergio Agüero"),0,10);
echo $src;
gives:
4960 MALMEDY
Then when I apply echo strip_tags($src);
gives me:
4960Â MALMEDY
The SPACE was replaced by  character:
What Do I do wrong ?
It looks that if I use
$src = utf8_decode($src); strip_tags works correctly.
Any rule I should know when to apply utf8_decode ?
Try:
header('Content-type: text/plain; charset=utf-8');
Please try this
$text_top = strip_tags(trim(html_entity_decode($str, ENT_QUOTES, 'UTF-8'), "\xc2\xa0"));
I need help with encoding "Title" tag. I have name with special character, like "ě, š, č, ř, ž, ý, á, í, é" and in demo.browse.php is working. There is my code and I dont know, where is the problem, please, Can you help me? :) thanks
<?php
require_once('getid3.php');
$PageEncoding = 'UTF-8';
$getID3 = new getID3;
$getID3->setOption(array('encoding' => $PageEncoding));
$FullFileName = "test.webm";
$ThisFileInfo = $getID3->analyze($FullFileName);
getid3_lib::CopyTagsToComments($ThisFileInfo);
echo '<html><head>';
echo '<title>getID3() - (sample script)</title>';
echo '<meta http-equiv="Content-Type" content="text/html;charset='.$PageEncoding.'" />';
echo '</head><body>';
echo htmlentities(!empty($ThisFileInfo['comments_html']['title'])?implode('<br>', $ThisFileInfo['comments_html']['title']) : chr(160));
echo '</body></html>';
?>
resoult is: "V zajet& #237; d& #233;mon&# 367;"
And original is: "V zajetí démonů"
I try iconv(); and utf8_encode(); dont work. Thanks
You call htmlentities on the result yourself. This call converts diacritics to respective HTML entities.
Use htmlspecialchars instead.
When I try to change from windows-1256 to utf8 text become like that
ÇáÑßä ÇáÚÇã ááãæÇÖíÚ ÇáÚÇãÉ
I'm trying to change the encoding of webpage I grabbed using file_get_contents.
header('Content-Type: text/html; charset=utf-8');
This sounds like a job for iconv
$output = iconv("ISO-8859-1", "UTF-8", file_get_contents($url));
Since I can't know what your content is, you might have to try UTF-8//TRANSLIT and UTF-8//IGNORE
Although I don't know Arabic, this might point you in the right direction:
$str = 'ÇáÑßä ÇáÚÇã ááãæÇÖíÚ ÇáÚÇãÉ';
$str = iconv("windows-1256", "utf-8//TRANSLIT//IGNORE", $str);
echo $str;