1

I'm using various php codes in most of html files from our website. I want html files treated as php, thefore I've added this line to the .htaccess

AddHandler application/x-httpd-php5 .html .htm .php

Now, everything is fine, my html files evaluate the php code and i am happy. However my happiness was short lived because this solution created another problem. Character Encoding got messed up and now although i declared

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 

characters are being displayed like this on the website

c�nd �ncearc? s? �?i scad?

My question is how can i evaluate php in the html files and NOT messing up my Character Encoding of the Html pages.


Requested to show code:

<h1 class="Normal-P"><span class="Normal-C-C0">&quot; Cele </span><span class="Normal-C-C1">3 MARI GREŞELI</span><span class="Normal-C-C0"> pe care majoritatea le fac atunci când încearcă </span></h1>

<h1 class="Normal-P"><span class="Normal-C-C0">să îşi </span><span class="Normal-C-C1">scadă colesterolul în mod natural </span><span class="Normal-C-C0">&quot;</span></h1>

results in this

Click pe butonul din stanga jos pentru redare....Asteapt? c�teva secunde p�n? cand acest video se �ncarc?

13
  • How PHP files themselves are encoded? Commented Aug 13, 2013 at 21:26
  • they are also also encoded in utf-8 Commented Aug 13, 2013 at 21:30
  • 1
    @RaduS You may also have a byte order mark issue it's a possibility and should not be left out of the equation. Commented Aug 13, 2013 at 22:14
  • 1
    @RaduS I think what the problem may be now, is the type of editor you are using. I created a file with plain Windows Notepad, and it did not show the characters correctly. However, when I pasted my codes into Notepad++ and saved it as "Encoding/Encode in UTF-8 with or without BOM", it displayed correctly. Visit notepad-plus-plus.org to download it if you wish. That's the best advice I can give you. Good luck. Commented Aug 13, 2013 at 22:34
  • 1
    @RaduS You're welcome. I learned that lesson the hard way also. Has your problem been resolved? Commented Aug 13, 2013 at 22:39

2 Answers 2

1

I think what the problem may be now, is the type of editor you are using.

I created a file with plain Windows Notepad, and it did not show the characters correctly.

However, when I pasted my codes into Notepad++ and saved it as "Encoding/Encode in UTF-8 without BOM" (byte order mark), it displayed correctly.

Visit notepad-plus-plus.org to download it. It has different encoding formats.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Fred, i just finished correcting all files...it was a painful process but worth it ;)
@RaduS That's great news. Yes I agree it is a lot of work, that is why I like to use includes as navigation menus, etc., so I only have 1 file to edit if I need to modify something globally. I take care of some rather large websites and I would not be happy to edit 100's of files per server. All the best, cheers!
0

The problem seems to be that your HTTP Content-Type header needs to also set UTF-8 explicitly.

To do that without modifying your files, in your php.ini, add/change

default_charset = "UTF-8"

Alternatively, right before you're about to send output, in PHP, do:

header('Content-Type: text/html;charset=UTF-8');

Example start of an HTML file:

<?php
header('Content-Type: text/html;charset=UTF-8');
?><!DOCTYPE html>
<html>

2 Comments

thank you @boen_robot I tried the first variant in the php.ini and it didn't help or maybe i didn't do it right. I want to implement the second suggestion you mentioned but i don't quite understand where specifically you want me to put the line header('Content-Type: text/html;charset=UTF-8');
At the top of HTML files, before any content (including DTD and whitespace), within a "\<?php" block. I've edited the answer above with a more complete example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.