开发者

PHP: including pages - html tags or not?

I'm designing a template for a webpage and I'm building separate parts of the template in different pages that will all be included in one page (ie, leftdiv.php, maindiv.开发者_Python百科php, header.php, footer.php etc). The website will contain Greek characters and I'm using utf-8 encoding.

Now I have leftdiv.php which contains greek chars but I've left out the html & meta tags that define the page encoding and as a result, I'm having problems displaying the page in the right encoding, probably because when index.php requires leftdiv.php, there isn't a meta tag for the proper encoding. Should I leave the meta tags on each included file or not? What other options do I have?


Meta tags doesn't matter.

You have to set up encoding in the real HTTP headers, not in meta substitution.
So, set your encoding in the PHP code by

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

and leave meta tags alone.

I am also wondering why you're using so much template files (leftdiv.php, header.php, footer.php etc) instead of placing them all in one main template.


My guess is that it goes wrong when uploading the file. Try binary mode (ftp), as some characters may not be ascii chars.

Further; don't worry about meta tags etc. in a template part; when outputting to the browser, all parts are concatenated by php and sent as one html page. The browser doesn't know anything about your different parts, just sees the whole picture. So check the html source in your browser. If the source is properly marked up, and the proper meta tag is in the , everything should be allright. To test it, just upload a simple html file. If it works, then extend it to different parts.


You have to store the files with UTF-8 encoding on your disc. Then the meta tag is okay without sending extra header.

<meta charset="UTF-8" />


Meta tags should be only in the head section of a page. And by page I mean the document that is shown by your web browser, not the PHP scripts behind it. So don't put meta tags in footer.php for example.


The browser doesn't know anything about your different parts, just sees the whole picture. So check the html source in your browser.


if you set header('Content-type: text/html; charset=utf-8'); with page by saved using UTF-8 encoding everything will be fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜