Hi,

I don't know much about php, since I didn't need it. Now though I need to make one small change in .php file - change some text that gets displayed.
This text is in UTF-8 Format with letters like ā š ķ , etc I've changed text inside of this php document, but after saving and re-uploading this file letters like ā š ķ are displayed just like a s k.
I know that in html you just needed to add charset=utf-8 and those letters would display, but what do I do in .php ?
I did look around on internet , tried using this piece of code

header('Content-Type: text/plain, charset=utf-8');

but that didn't help, letters like ā š ķ are simpy displayed as a s k

How could I get this to work ?

Dani AI

Generated

Short diagnostic note and practical checks based on the thread: the two symptoms shown here — diacritics being replaced by plain letters and the later "Cannot modify header information - headers already sent" warnings from WordPress — almost always come from a file encoding/output problem. 's pointer to use an editor that understands UTF-8 and 's followup about saving without a BOM are the right direction. Below are concise clarifications and a short checklist to avoid the common traps.

BOM and header timing: some editors add a UTF-8 BOM (three invisible bytes) at the start of a file. Those bytes are sent as output immediately, so any later call to header() fails and generates "headers already sent". Also check for any stray blank lines or spaces outside PHP tags. Use the correct header syntax and send it before any output:

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

For a PHP-only file, omit the closing ?> tag to prevent accidental trailing whitespace:

<?php
// PHP-only file: no closing tag
// ...script...

Quick troubleshooting checklist

  1. Confirm the file is actually saved as UTF-8 without BOM (editors like Notepad++ show the encoding and can convert it).
  2. Inspect the first bytes with a hex tool (EF BB BF indicates a BOM) and remove them if present.
  3. Remove any blank lines or spaces before <?php or after a ?> (or better: remove the closing ?> in pure-PHP files).
  4. Ensure the correct Content-Type header is sent (use text/html; charset=utf-8 for HTML) and that header() runs before any output.
  5. Since this touched /wp-comments-post.php, avoid editing core WordPress files long-term; apply fixes in theme templates, child themes, or plugins so updates are safe.

Summary: the encoding + BOM + early output combination explains both the lost diacritics and the header warnings. The steps above reliably catch and fix those causes — which is why 's and 's approach resolved it and helped other members like .

Recommended Answers

All 7 Replies

The letters are not coming out of a database I presume. Just an echo in the php file where these letters should be displayed in a browser?
If so, you can repair the problem by re-opening the php file with a editor that understands utf-8. Under Windows you could even use notepad for this. See image.

Yes, they aren't coming out of database.

This worked, thank you, I didn't think it would be so simple ! :)

Would be nice if dreamweaver also had this simple function in save as window.

Ah dreamweaver... Never heard anything good about it.

It seems this thread is solved. Could you please mark it as solved then. Thank you.

Of course. Thanks again !

I have another problem after saving as utf-8 using notepad. Letters work, but after saving as utf-8 this error below appears:

I backed up original file of course, and after restoring problem goes away. I tried saving original file as utf-8 (nothing else, just saving) problem appears. What could be the problem here ?

Warning: Cannot modify header information - headers already sent by (output started at /home/bcgroupl/public_html/majaslapa/wp-comments-post.php:1) in /home/bcgroupl/public_html/majaslapa/wp-comments-post.php on line 88

Warning: Cannot modify header information - headers already sent by (output started at /home/bcgroupl/public_html/majaslapa/wp-comments-post.php:1) in /home/bcgroupl/public_html/majaslapa/wp-comments-post.php on line 89

Warning: Cannot modify header information - headers already sent by (output started at /home/bcgroupl/public_html/majaslapa/wp-comments-post.php:1) in /home/bcgroupl/public_html/majaslapa/wp-comments-post.php on line 90

Warning: Cannot modify header information - headers already sent by (output started at /home/bcgroupl/public_html/majaslapa/wp-comments-post.php:1) in /home/bcgroupl/public_html/majaslapa/wp-includes/pluggable.php on line 868

Found solution to this problem. colweb was right about saving as utf-8, but it's important to save as utf-8 without bom(which adds invisible characters to the document). I found that notepad ++ does this job really well.

i had the same problem and i've been working on it for 7 hours. wonderland and everyone - thank you !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.