Jump to content


Photo

Html Code Line <meta charset="utf-8" /> Seems To Cause PHP Issue


  • Please log in to reply
3 replies to this topic

#1 phdphd

phdphd

    Advanced Member

  • Members
  • PipPipPip
  • 111 posts

Posted 12 November 2013 - 09:50 AM

Hi All,

I would like to share a strange experience with you and get your opinion about it. The issue is that a php file is not processed as expected, apparently due to the html code line <meta charset="utf-8" />, hence the presence of my post in the HTML section of the Forum. My config is PHP 5.3.25/Mysql 5.6.11.

I am trying to adjust my website so that it is fully utf-8 aware. I am presently adjusting all my php files for that purpose.

 

Basically, I have an index.php file with links to different processes the user can start. Every process involves a series of forms and is made up of one file (called process-to-do.php) and a series of php files that the process-to-do.php file calls one after the other via include file instructions (every included file contains a form). All works great.

In Notepad++ (with default encoding previously set to utf-8 ) in order to make every php file utf-8 aware, and to avoid retyping all the code, I sequentially created a new php file, saved it with the same name as the legacy non-utf-8 file, and pasted a basic html5 code structure in it. Then I pasted the legacy pieces of code and made utf-8 adjustments where appropriate.

 

FYI the basic html5 code structure I insert is

<!DOCTYPE html>
<html lang="fr">
    <head>
        <meta charset="utf-8" />
        <title>Titre</title>
<link rel="stylesheet" href="style.css">
    </head>
 
    <body>

    </body>
</html>

This process worked great until a certain file was called for inclusion. What happens visually is that this file is not displayed and that the index.php file is displayed instead. In other words the user is redirected back to the starting point where they choose what to do, without the ability to validate the form in the called file and to go to the next step. At first sight it seems that the called file is just ignored. But actually it is not. I noticed that the php contents of the file is successfully processed (there is some php that sends some data to a database and that job is done).

I first thought that some php code was corrupted and causing the issue. I deleted the php code and I reexecuted the process. Again, the file would not display and the user would be redirected back to the starting point (index.php file). This indicated that php code was not causing the issue.

OK. So I thought the form html code itself was corrupted. I deleted it and I reexecuted the process with only the basic html5 code structure in the file. Again, the file would not appear and the user would be redirected back to the starting point (index.php file). This indicated that the form html code was not causing the issue.

OK. So I thought "let's do it the other way by keeping only the form html code, without html5 code structure". I reexecuted the process and that time, the file displayed, though with incorrect accent formatting due to the absence of the html utf-8 formatting.

To go further I decided to add just the head section to the file to see if I could recover the utf-8 formatting. Failure again : the file would not appear and the user would be redirected back to the starting point.

So I added the doctype and the html tags, without the head section. That time, the file displays again, though with incorrect accent formatting due to the absence of the html utf-8 formatting.

Then I added the head section without the <meta charset="utf-8" /> line to get a 99,999% confirmation that this single line was causing the issue. As expected, the file displayed again, though with incorrect accent formatting due to the absence of the html utf-8 formatting.

I made a final test -BTW congratulations to all of you who reached that point in my post :happy-04: - by inserting the header('Content-type: text/html; charset=utf-8'); php piece of code at the beginning of the included php file, and then the file was correcty processed and displayed.

 

My questions are (a) why can a mere <meta charset="utf-8" /> line apparently cause such an issue, and (b) why in this included php file and not in the previous ones in the sequence ?
 

Thanks!



#2 AbraCadaver

AbraCadaver

    Cracka Memba

  • Gurus
  • 1,887 posts
  • LocationThe Republic of Texas

Posted 12 November 2013 - 11:48 AM

That was a long post with surprisingly little information.  Error reporting on?  What errors?

 

Just a shot in the dark, are you using sessions and are you saving the BOM in your files?

 

Notepad++:  Settings > Preferences > New Document > UTF-8 without BOM, Apply to opened ANSI files?  The BOM will cause issues, especially with sessions.


Edited by AbraCadaver, 12 November 2013 - 11:49 AM.

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.

#3 phdphd

phdphd

    Advanced Member

  • Members
  • PipPipPip
  • 111 posts

Posted 12 November 2013 - 12:39 PM

Thanks for your answer. Yes, I use sessions. Files are saved without BOM. No errors reported. (To be more precise there is a warning reported about the use of the php date function in the file, but as I wrote in my post, the issue also occurs when the file contains no php code).

 

BTW I see no "Apply to opened ANSI files" equivalent option in my Notepad++ French version. However "ANSI as UTF-8" appears at the bottom right of Notepad++ status bar.

 

Edit : I misread your Notepad++ sequence. Yes, the "UTF-8 without BOM, Apply to opened ANSI files" option is selected.


Edited by phdphd, 12 November 2013 - 12:52 PM.


#4 AbraCadaver

AbraCadaver

    Cracka Memba

  • Gurus
  • 1,887 posts
  • LocationThe Republic of Texas

Posted 12 November 2013 - 01:32 PM

Well, we'll hope that somebody with more charset knowledge than me reads this, as that is the extent of my knowledge there.


Edited by AbraCadaver, 12 November 2013 - 01:32 PM.

mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com