homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

changing basic html structure with PHP

5+ Year Member

Msg#: 4038622 posted 11:34 am on Dec 7, 2009 (gmt 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 :)



5+ Year Member

Msg#: 4038622 posted 12:36 pm on Dec 7, 2009 (gmt 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.


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

Msg#: 4038622 posted 11:00 am on Dec 10, 2009 (gmt 0)

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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved