My site is all php pages, since it's all database stuff. However, I'm having trouble putting the pages into no quirks mode... I did the regular thing:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
and this doesn't work. If I create an html page with the same code, of course it works.
So this leads me to believe that I can only to off quirks mode in html pages? Maybe this is a stupid question, and I don't need to turn off quirks mode in php page?.. Please help, <form> keeps breaking a line, and I've tried multiple fixes, but I'm thinking it has to do with the site being in quirks mode.
It doesn't matter how the page is rendered, PHP or static. I suspect your issue is in the doctype declaration. Are you sure the php isn't outputting any characters like a line break before the doctype?
Your PHP script may be outputting some Content-Type header that tells the browser the page is some other formatting than the doctype specifies. I'm not sure how the browser is supposed to resolve such a conflict. I'm also not sure how you've got PHP set up to output the Content-Type headers, but if you look in the PHP manual for headers, you'll probably be on the right track. The setting may also be in your web server config.
If you're doing XHTML, shouldn't you have an XML declaration above the doctype?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
Also, if you're serving XHTML, be sure the content type is text/xml, not text/html. That's a common error. XHTML is XML and must be served as such or most browsers will ignore the declaration and go with quirks mode.
(Better yet, don't use XHTML, use HTML5.)
If that doesn't fix it, I think Pete Michaud must have the right idea. Check with View Source to see what actually got sent to the browser.
Yes, so apparently I was adding the code to the wrong page. And the page I should have been adding it to had code that was conflicting. So thanks, it works now.. the stupid page break is still there, like to create new line's no matter what css I apply, but atleast the site is standardized now. Thanks everybody!
Related
I'm studying database systems, and we are accessing the database using php on a webpage. This .php file has been given by the teacher for us to use to write basic php in. I tried googling "!include" but haven't been able to find an example like this one. I realize that another php file is being accessed, but I don't understand why it would be at the top of the page instead of within the php code itself. Could someone explain what is going on with the code below or point me to a website that explains it?
<!include = "/home/DBinfo.php">
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
It's very strange syntax due this manual about phptags. There are these tags:
standard choice <?php ?>
shorten tags <?=, <?
asp tags <%, %>, <%=, and the script tag <script language="php"> which was removed in php version 7.0.0
But there exist webserver ssi includes with directive like <!--#include virtual="/footer.html" --> in some webservers (Apache, nginx, ...). But this command <!include = "/home/DBinfo.php"> have different view.
Try to replace your code with this proper opening php tag and using include directive:
<?php include "/home/DBinfo.php";?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
This code should work in any normal environment.
I found a Webpage saved as something.php. But the source code tells me <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
I also found out that PHP code does not work on the webpage.
What is the need for making the file extension PHP if HTML is used?
(Not exactly HTML, but XHTML)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
What is the need for making the file extension PHP if HTML is used?
(Not exactly HTML, but XHTML)
Considering your comments so far, particularly you stated there is no PHP; you can just change the file extension to XHTML. You can always change it back.
I wonder what other PHP files exists where you "found" this page and why. Assuming someone before you developed the site, there is probably a reason they used PHP file extensions.
Unless your host doesn't support PHP, then you should be able to run php code anywhere on that page by placing it inside "" tags. The 'Content-type' isn't relevant to whether PHP can run or not. Try adding the following code somewhere in your page:
<?php echo "Hey there, I'm a friendly PHP string!"; ?>
add this <?php echo "Hello!"; ?> in your page to test, and make sure that your server is running, and normally it works
Are you using a wamp/mamp server? Have you tried to turn it on?
These code are meta tags
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and it has nothing to do with php unless you have included a php script to it.
Html/XHtml will run even though you are not using a php server. All php files has a .php file extension and will run only if you use a server like wamp for windows or mamp for mac.
You can still use html/xhtml code in a .php file.
For example I have an <h1>This is h1</h1> tag and you want to make it dynamic, you can put <?php ?> inside the tag and echo it out to display, <h1><?php echo "This is h1"; ?></h1>.
In case you want to put html code inside a php script, you can do it like this
<?php echo "<h1>This is h1</h1>"; ?>
You can learn more about php and other programming languages by the help of google. Just take your time, relax and enjoy learning. Don't pressure yourself, remember learning is not a medicine that when you take it, it will work in a few minutes. Learning takes time and practice. Enjoy coding.
I want to see an error which will happen if I send not valid(according to XHTML standard) markup to browser. I'm using google chrome as browser, apache as server and php as script language. I've created a script with such lines:
header('Content-type: application/xhtml+xml');
$content = <<< XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />
<title>XHTML</title>
</head>
<BODY>
<P>Lorem ipsum dolor sit amet...</P>
</BODY>
</html>
XHTML;
echo $content;
It should be incorrect because of BODY from capital letters.
But I'm getting correct results, because I see that google chrome accept such mime-types:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
So it interprets result as text/html and everything is fine.
I want to make this document invalid. How I can remove text/html from accepted headers at google chrome? Or I am wrong at something?
UPD
When I removed closing BODY tag, I can see an error. Seems that browser don't care about such little mistakes.
You are misdiagnosing the problem.
The accept header tells the server that HTML and XHTML are equally preferred.
Your script ignores the accept header entirely and sends an XHTML content type
XML parsers will not throw parsing errors on well-formed documents, even if they are invalid
Current browsers (as far as I know, I haven't experimented with this in a while) will fall back to an HTML parser if they get non-well-formed XHTML (because telling end users that page authors made a type is, 99/100 times, unhelpful).
If you want to detect validity errors, then use a validator (which is a tool designed to detect them) and not a browser (which is a tool designed to render web pages and recover from author errors).
So it interprets result as text/html and everything is fine.
I want to make this document invalid. How I can remove text/html from accepted headers at google chrome? Or I am wrong at something?
Although the browser will send several content types in the Accept header, the server is open to choose one of them in the response.
This is done by setting the Content-Type header in the response (As you do)
header('Content-Type: application/xhtml+xml');
This tells the browser that response is an XHTML document. You have no further chances to influence the browsers validation process.
Seems that chrome is too much forgiving and accepts the uppercased <BODY>.
A weird thing when I use PHP Smarty.
It seems the encoding of php file affects the css.
PHP file (ANSI)--test2.php
<?php
include_once("inc/smarty_inc.php");
$smarty->display('test.tpl.htm');
Smarty file(ANSI)--test.tpl.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JPR</title>
</head>
<body>
<div style="width:500px;height:200px; background-color:Red;margin:auto;">
test
</div>
</body>
</html>
when these two files are ANSI. The div shows at the center of the page.(both IE and firefox)
when one of them is converted into utf-8. The div shows at the left of the page.(only in IE ,It's OK with Firefox)
What's the matter with it? How to make it OK in IE with uff-8?
You are saving the file in UTF-8 with BOM, this causes the first bytes in the response to be the bytes for byte order mark, and not doctype. When IE doesn't see doctype first, it goes to quirks mode, where the box model is different.
You need to convert it into UTF-8 without BOM. This depends on the text editor or converter you are using.
If the content type and character set are declared in the PHP header, is there a reason to have them again in the usual HTML DTD?
<?php ob_start( 'ob_gzhandler' );
header('Content-type: text/html; charset=utf-8'); ?> // here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> // and here
...
If you are sending the charset in the headers, the is no need to repeat it in the HTML markup.
It is better to send this information in one place (DRY principle), as if the charsets conflict (ie. a header with UTF-8 and a meta with iso-8859-1), the browser will probably go to quirks mode.
Having said that, some automated tools (web scrapers) may not look at the header and deduce the page encoding only by the meta tag.
It is important to keep both the header and meta tag the same for each page - mixing different charsets may confuse browsers and cause display issues.
Having the charset in the HTML source may be helpful if someone decides to save a page, or for web scrapers :). libxml looks up the meta tag to determine the charset to use when parsing the markup. Show your fellow developers some web scraping love.
If you declare it in the HTTP headers, then it will survive transcoding by proxies and won't ever trigger a "Whoops, I guessed the wrong encoding, restart parsing from top" situation in browsers.
If you declare it in the body of the document then it will survive being access outside of HTTP (or another system with content-type headers, such as email).
If you declare it in both then you get the best of both worlds so long as no transcoding happens.
Note that if you don't use UTF-8 or UTF-16 then the XML spec requires that you specify it in the XML prolog (and that using an XML prolog will trigger Quirks mode in IE6).