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.
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
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 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.
Actually, I have googled a Lot, And I have explored this forum too, but this is my second day, and I could not find the solution.
My Problem is that I want to convert the Html Codes
باخ
to its equallent unicode characters
خ ا ب
Actually I do not want to convert all the html symbols to unicode characters. I only want to convert the arabic / urdu html code to unicode characters. The range of these characters is from ؛ To ۹ If there is no any PHP function then How can I replace the codes with their equallent unicode character in one go?
I think you're looking for:
html_entity_decode('باخ', ENT_QUOTES, 'UTF-8');
When you go from ب to ب, that's called decoding. Doing the opposite is called encoding.
As for replacing only characters from ؛ to ۹ maybe try something like this.
<?php
// Random set of entities, two are outside the 1563 - 1785 range.
$entities = '؛<لñ۸۹';
// Matches entities from 1500 to 1799, not perfect, I know.
preg_match_all('/[5-7][0-9]{2};/', $entities, $matches);
$entityRegex = array(); // Will hold the entity code regular expression.
$decodedCharacters = array(); // Will hold the decoded characters.
foreach ($matches[0] as $entity)
{
// Convert the entity to human-readable character.
$unicodeCharacter = html_entity_decode($entity, ENT_QUOTES, 'UTF-8');
array_push($entityRegex, "/$entity/");
array_push($decodedCharacters, $unicodeCharacter);
}
// Replace all of the matched entities with the human-readable character.
$replaced = preg_replace($entityRegex, $decodedCharacters, $entities);
?>
That's as close as I can get to solving this. Hopefully, this helps a little. It's 5:00am where I am now, so I'm off to sleep! :)
did you try the utf-8 encoding in html head?
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
try this
<?php
$trans_tbl = get_html_translation_table(HTML_ENTITIES);
foreach($trans_tbl as $k => $v)
{
$ttr[$v] = utf8_encode($k);
}
$text = 'بب....;خ';
$text = strtr($text, $ttr);
echo $text;
?>
for mysql solution you can set the character set as
$mysqli = new mysqli($host, $user, $pass, $db);
if (!$mysqli->set_charset("utf8")) {
die("error");
}
I have a form and in a textarea I want to display some text that have some spanish characters but encoded as html. The problem is that instead of the spanish character it displays the html code. I'm using htmlentities to display it in the form. my code to display is:
<?php echo htmlentities($string, ENT_QUOTES, "UTF-8") ?>
Any idea or I just shouldnt use htmlentities in a form? Thanks!
EDIT
Lets say $string = 'á'
When I just do <?php echo $string ;?> I get á
If I do <?php echo htmlentities($string, ENT_QUOTES, "UTF-8") ?> I get á
I'm so confused!
You can try explicitly adding content type at the top of your file as below
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
if it's already encoded as html then you need to decode it now..you can use html_entity_decode($string);
Your string to be echoed in the form should be á as returned from database and not á
$string = 'á'; // your string as fetched from database
echo html_entity_decode($string);// this will display á in the textarea
and before saving to database you need to
htmlentities($_POST['txtAreaName'], ENT_QUOTES, "UTF-8"); // return `á`
If I understand you correctly, you need to use...
<meta charset="utf-8">
in your page header, and then...
<?php echo html_entity_decode($string, ENT_QUOTES); ?>
This will convert your HTML entities back to their proper characters
You might be looking for htmlspecialchars.
echo htmlspecialchars('<á>', ENT_COMPAT | ENT_HTML5, "UTF-8");
outputs <á>.