Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

changing basic html structure with PHP

11:34 am on Dec 7, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 15, 2008
votes: 0

I have a rather strange problem, I operate a site where some pages are in French and some are in English, thus I have the need to change main "html" tag from page to page.
I (obviously) decided to do so with PHP, but it seems to affect the load time of the page. No idea why this happens, because it seems to be illogical.

Let me provide you the bit of code:

$language = "fr";
$language = "en";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="<?php echo $language;?>" xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Here you can see the small manipulation I make in the "lang" attribute of the "html" element.
When I add it as so - my page sometimes shows blank white screen for a part of the second and then loads the page.
You could say it looks like a brief white blink. I guess it doesn't do any damage, but it sure looks anoying. This ONLY happens if I try to manipulate the "html" code by PHP. I tested it with and without at least 100 times.

If I leave it static as this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

It always loads without the blank white screen.
What could be causing this?
I'm testing it on localhost, firefox.

Shouldn't a page be pre-compiled by PHP on the server and then simply outputted to the browser?
Is there any unknown rule that I'm not aware of? I thought it would be perfectly fine to make such changes with PHP.

If you had similar situations or have a clue on what could be causing this behavior, please comment :)

12:36 pm on Dec 7, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 15, 2008
votes: 0

I found the solution. So if anyone stumbles upon the same problem:
echo the whole head thing, everything.

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="'.$language.'" xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="'.$language.'">

When you echo the whole upper html tags, there are no more "hiccups" like before. Still interested to find out why they were happening in the previous code..
But this solution works well.

11:00 am on Dec 10, 2009 (gmt 0)


WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
votes: 2

First, I'm in agreement with you ... that really doesn't make sense. All that processing and output happens server-side and should not make any difference whatsoever, as you have stated. I notice you are not sending out the XML declaration, but that probably isn't it either. Are you actually sending out utf-8 Content-Type headers too? Use LiveHttpHeaders extension in Firefox to see. Lastly, that html element should probably also contain the xml-lang attribute. I always put it in, anyway. Along with the text direction ... but that's me.



Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members