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.
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.
This include is not working in IE:
<?php
include_once 'localization.php';
?>
<!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"/>
<title>Global Colleague</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/><!--Start Kampyle Exit-Popup Code-->
<script type="text/javascript">
Calling an array inside localization.php
<?php echo l('content_p3'); ?>
EDIT: I tried the same file in another folder and it worked
"Not working" is very generic. What is it that you expect and what is actually happening? You may want to turn error reporting on and see if any error is reported. In (X)HTML, nothing should be printed before the doctype. Are you trying to add something to the HTTP response? Typically, the browser shouldn't effect how PHP outputs your code unless you've added some code to respond to the user agent which is not always wise.
Perhaps, when you tried your code in another directory it wasn't able to find the offending script as it is included by a relative path. Try removing the include in the original file and see if it "works".
The following way 100% work for you:
1) Install (Open Source) Notepad++ On your PC
2) Open the file in it
3) Go to encoding and select (Encode in UTF-8 Without BOM)
4) Then click save
5) Now it can work on (Chrome) and (IE)
:)
i am new to .php. I would like to know what are all the ways we can create User Controls (How we do it in asp.net). This found with include in php, but i need to pass parameters to it and use those parameters in that php include file.
I would strongly encourage you to use a php framework for web development. Standalone php is too generic and unstructured to be effective in development.
To answer your question, if you decide to use a framework such as Symfony you will find it comes equipped to handle "User Controls" using "Partials", "Components", and "Widgets".
See http://www.symfony-project.org/book/1_2/07-Inside-the-View-Layer for more information.
--
If you decide not to use a framework, then your best bet would be to put the HTML code, in an include file (e.g. myControl.inc.php) and then include it manually in your main layout using:
Again, I'd strongly discourage anyone from developing a php application without a framework.
I remember I did an experiment to mimic ASP.NET behaviour using PHP + JavaScript.
A vague example:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict (jaFramework-Edition)//EN//"
"http://www.joelalejandro.com/ja-xhtml/ja-xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ja="http://www.joelalejandro.com/ja-xhtml/" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript" src="jaXHTML.js"></script>
</head>
<body>
<ja:MySQLServer
id="MySQL1"
ConfigFile="mysql1.conf">
</ja:MySQLServer>
<ja:Grid
id="Grid1"
UsingConnection="MySQL1"
DataSource="urminute_com.mp_songs">
</ja:Grid>
<script>
alert(window.Grid1.DataSource);
</script>
</body>
I took XHTML 1.0 Strict's definition file and added the "ja:" tags. Then, using Javascript DOM and AJAX, I replaced the tags with the content that I was required to deliver.
I don't know exactly how efficient the solution is, yet is XHTML-compliant.
Just my two cents on the subject.
Can't this be achived using "get" parameters in the include call? Something like:
include 'control.php?param1=value1';
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!
I don't know why every time I try to include my header using PHP’s include there's a top margin. I checked it using Firebug and it says there's a 22px offset margin on the top. Is anybody experiencing this problem? I think it's a CSS propiety: top: 22px. But nothing can change it even if I write h1 style="top: 0px; margin-top: 0px;". I think it's a php-CSS mystery that will never be solved.
edit: The only way to get rid of that top margin offset or whatever it is, is to add the follow properties to the H1: top: 0px;
position: absolute;
Will those properties generate more problems in the future?
is there a better way to solve this top margin-offset problem?
edit2: I think there's a problem with the encoding. Is there a conflict between the encoding of the included file (header.html) and the index file?
My index goes like this:
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body>
<div id="page-wrap">
<?php include_once("header2.html"); ?>
</div>
</body>
</html>
With this CSS:
* {
padding: 0px;
margin: 0px;
}
My header.html (the one that’s being included):
<h1>Header 2</h1>
And that’s the output:
<!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 content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link rel="stylesheet" type="text/css" href="style2.css" />
</head>
<body>
<div id="page-wrap">
<h1>Header 2</h1> </div>
</body>
</html>
God its so simple that I really dont know where the top margin is coming from (in all browsers).
It only happens when I use php includes.
The source code looks the same as when I dont use php include.
This is pretty weird, but I copied & pasted your output HTML into Notepad++, and there was a strange character just prior to the h1. When pasting it into Notepad, the h in the h1 was subscripted.
Therefore, it looks to me like you may have an erroneous (or unexpected for PHP) character in your included HTML (or in the PHP including it). My suspicion? The dreaded UTF-8 BOM. Try to change the encoding of your included HTML file to eliminate the BOM (which I've always had problems with when dealing with PHP).
Edit: Yep. Just verified with a hex editor. There's a byte-order mark at the beginning of your included HTML. I don't know which editor you use, but you should have the option to change your text encoding settings.
See this for more info about PHP & the BOM.
You ought to post your generated HTML, like by copying what you see when you select "View Source" from your web browser. Oftentimes, I've seen mysterious blank lines in PHP-generated HTML because PHP is configured to output errors and warnings. Even if this is not caused by that, we can more-easily diagnose the problem if we see the outputted HTML.
I experienced the same problem...so what I did to fix it was to add an html opening comment at the beggining of the first file and an html closing comment at the beginning of the second file. This encloses the BOM (or whatever is appearing in between the files) inside a comment so it's not outputted in html.
For example:
#header.php
<?php ?>
<html>
<!--
#body.php
<?php ?>
-->
<body>
...
I tried to fix the problem converting between encoding formats in notepad++ to no avail. So this is only a temporary fix til I find a better solution to the problem.
well, without knowing what's in your php include, it's hard to tell, but make sure there's no CSS inside of it. also make sure that CSS you're loading is getting found and loaded. i debug by changing the background color or something else visual so u can be sure it's loading.
i'd bet anything that it has nothing to do with the php include it's self. like previously mentioned, there may be some css in the included file that is doing it, but i've never seen php anything like what you are describing.
i would look at the doctype declaration [temporarily remove it to see what happens], and remove the current html declaration tag and replace it with a plain <html> tag [again just temporarily, to debug]
A lot of times an extra new line will be at the end of a PHP script file you are including after the ?> tag. This will cause an extra character to be included in the generated output. You can remedy this problem by not having a closing ?> tag at the very end of your file. PHP knows to "assume" that it's closed.
Do you have the option to give us a link? I just tried locally a couple of things and you may get this "unwanted" new line for apparently "no reason" at all between your content and the "doctype" declaration, if there is a nonprintable character. Try to delete all characters after the ">" and take a look at it with a hexeditor to make certain of it. Please provide us more info.
Thats very interesting, because I just used your markup and your css. I also put it into an php file and included a html file. But there is no margin. Nowhere.
So make sure your browser is able to find the css file with
* { margin: 0; padding: 0 }
And I suggest you to use a reset sheet like this one - http://meyerweb.com/eric/tools/css/reset/index.html.
p.s. if you own some webspace, put it online and send us a link.
Dreamweaver drives me nuts with it's automatic BOM additions. Here's the fix:
http://www.adobe.com/support/documentation/en/dreamweaver/mx2004/dwusing_errata/dwusing_errata2.html
I am using notepad and I selected from the menu -> Encoding->Encoding with UTF-8 without BOM and it worked just fine. This should be done for every included file. I think this is the solution to your problem. Have a nice evening.
I almost killed my keyobard trying to solve to problem.
Then I tried PSPad editor, change explicitly .inc or .php to UTF-8 and IT WORKED !!
I had one time this problem and here is the way to fix it - its really problem in charset.I have spent 10 hours to find it. In my situation I change at all php files(all php files, all tpl(if you have) files) charset from UTF-8 to UTF-8 without bom and save it and try then. After that you can also make at .htaccess string "AddDefaultCharset UTF-8".