Hello:
I'm writing my first php app and I have a problem.
Initially I put template type strings, such as HTML Headers and page
footers in a MySQL table and called them up with a php SQL query to
include them in the printed HTML, This worked great but then I learned
about includes and I tried using includes to put them into the HTML.
1. I assume that this is faster than the query method because that's
what people seem to do. Am I right about that?
2. The following string works as a query result but not as an include
file. Could someone be so kind as to explain to me why?
<?xml version="1.0" encoding="UTF-8"\x3f>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html>
The parser chokes on the first line. If I remove it the include works
fine.
Thanks,
Ken 5 1835
.oO(Ken) I'm writing my first php app and I have a problem. Initially I put template type strings, such as HTML Headers and page footers in a MySQL table and called them up with a php SQL query to include them in the printed HTML, This worked great but then I learned about includes and I tried using includes to put them into the HTML.
1. I assume that this is faster than the query method because that's what people seem to do. Am I right about that?
I guess so. A filesystem access should be faster than a server request.
2. The following string works as a query result but not as an include file. Could someone be so kind as to explain to me why?
<?xml version="1.0" encoding="UTF-8"\x3f> [...]
The parser chokes on the first line. If I remove it the include works fine.
You have short_open_tags enabled in your php.ini, so the parser treats
the first two chars of <?xml as the beginning of new PHP block, which
causes a parse error. Three solutions:
1) Disable short_open_tags in your php.ini.
2) Use PHP and a print or echo statement to print out the XML prolog:
<?php print "<?xml version='1.0' ...?>";?>
3) Simply remove the prolog. You only need it if you want to use another
encoding than UTF-8 (used by default) and no encoding information was
given in another protocol level, for example in the HTTP response
header.
HTH
Micha
On Sat, 18 Sep 2004 19:56:59 +0200, Michael Fesser <ne*****@gmx.ne t>
wrote: 2. The following string works as a query result but not as an include file. Could someone be so kind as to explain to me why?
<?xml version="1.0" encoding="UTF-8"\x3f> [...]
You have short_open_tags enabled in your php.ini, so the parser treats the first two chars of <?xml as the beginning of new PHP block, which causes a parse error. Three solutions:
1) Disable short_open_tags in your php.ini. 2) Use PHP and a print or echo statement to print out the XML prolog:
<?php print "<?xml version='1.0' ...?>";?>
3) Simply remove the prolog. You only need it if you want to use another encoding than UTF-8 (used by default) and no encoding information was given in another protocol level, for example in the HTTP response header.
Michael,
Thank you very much for your reply and explanation.
Is it odd that it works as a query result?
Ken
Ken wrote: Hello:
I'm writing my first php app and I have a problem. Initially I put template type strings, such as HTML Headers and page footers in a MySQL table and called them up with a php SQL query to include them in the printed HTML, This worked great but then I learned about includes and I tried using includes to put them into the HTML.
Why don't you try something like this:
class Whatever {
function Whatever() {
...
}
function output() {
echo "<!DOCTYPE ...";
echo "<html>";
output_header() ;
output_body();
echo "</html>";
}
function output_head() {
// output common header
...
}
function ouput_body() {
// output custom content
...
}
}
and then for every page you have
$whatever = new Whatever();
$whatever->output();
you can pass parameters to the constructor and then use them to further
customize the body output (say, maybe a page id, which determines what
include file contains the body) :)
Lüph
.oO(Ken) Is it odd that it works as a query result?
No, because to print out a query result you already use a print or echo
statement, i.e. you are inside a PHP-block. No problem with that. In
your example you try to write it out directly in a HTML-block without
PHP, but PHP interprets it wrong, hence the parse error.
Micha
On Mon, 20 Sep 2004 01:04:55 +0200, Michael Fesser <ne*****@gmx.ne t>
wrote: .oO(Ken)
Is it odd that it works as a query result?
No, because to print out a query result you already use a print or echo statement, i.e. you are inside a PHP-block. No problem with that. In your example you try to write it out directly in a HTML-block without PHP, but PHP interprets it wrong, hence the parse error.
Micha
Please bear with me while I try to grasp this. My include statement
is inside a php block as far as I can see:
<?php
if (!isset($_SERVE R['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="My Realm"');
header('HTTP/1.0 401 Unauthorized');
echo "Access to ITR Billing canceled";
exit;
}
else {
$userName = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
/* Connecting, selecting database */
$link = mysql_connect(" localhost", $userName, $password)
or die("Could not connect : " . mysql_error());
mysql_select_db ("ITRBilling ") or die("Could not select database");
/* Performing SQL querys */
$query2 = "SELECT userName FROM Users WHERE `userName` = \"$userName\ "
AND `password` = \"$password\ "" ;
$result2 = mysql_query($qu ery2) or die("Query failed : " .
mysql_error());
/* HTML Header */
include("HTMLHe ader.txt")
include("PageHe ader.txt");
etc...
} This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Yannick Turgeon |
last post by:
Oups! I did a typing error in my last post. Fixed.
-----------
Hello all,
We are currently changing our web server and, in the process, updating PHP
version from 4.3.0 to 4.3.5. The problem we've got is that our way to
include some files in other ones is no more working properly. The message we
are getting looks like: "PHP Warning: main(..\db.inc.php): failed to open
stream: No such file or directory in ..."
|
by: steve |
last post by:
I am quite frustrated with php’s include, as I have spent a ton of
time on it already... anyone can tell me why it was designed like this
(or something I don’t get)?
The path in include is relative NOT to the immediate script that is
including it, but is relative to the top-level calling script.
In practice, this means that you have to constantly worry and adjust
paths in includes, based on the startup scripts that call these...
|
by: alan |
last post by:
Dear all,
I have written my own function by C. And my development platform is
W2k with VC6.0.
Then I also defined a header file to extern declare this function.
After that, I include this header file.
The function is stored in C:\temp\myfun.c
int func(){
return 1;
|
by: atv |
last post by:
Alright, i have some questions concerning include files en global
variables.I hope someone is willing to answer these.
1).Why is it that if i define a global variable in a file, say main.c,
and i have also other functions defined in that file, i can use the
global in all functions, but once i split up the rest of the function in
other files, i cannot use the global? Isn't that strange, all the files
compiled should be treated as one...
|
by: Derrick Coetzee |
last post by:
It seems like, in every C source file I've ever seen, there has been a
very definite include order, as follows:
- include system headers
- include application headers
- include the header associated with this source file
For example, in a file hello.c:
#include <stdio.h>
| |
by: David Mathog |
last post by:
One thing that can make porting C code from one
platform to another miserable is #include. In particular,
the need to either place the path to an included file within
the #include statement or to very carefully define the
order in which paths are searched with command line options
on the compiler. Both can cause problems, especially when
dealing with complex software distributions.
It occurs ot me that by extending the C include...
|
by: Francois |
last post by:
Hi,
I think I found a bug with VS, and I've included a project
example of the problem I got.
I've got a project deep into a set of folders. The project
have an additional include library directory which is
pretty long and expressed relative to the project
(with ..\..\ and directory names).
|
by: Arpi Jakab |
last post by:
I have a main project that depends on projects A and B. The main project's
additional include directories list is:
...\ProjectA\Dist\Include
...\ProjectB\Dist\Include
Each of the include directories contain a file named "cppfile1.h".
In my main project I #include "cppfile1.h". I rely on the order of paths in
additional include directories list to get file cppfile1.h from ProjectA and
|
by: tshad |
last post by:
In my User control, I tried to do this:
***************************************************************************
<Script runat="server">
Public ClientName As String = "<!-- #include file =
...\includes\StaffingHeaders.inc -->"
</Script>
<%=ClientName%>
****************************************************************************
|
by: Tio |
last post by:
I have project in MFC(vc++) . There are files and classes:
classes:dialog1,dialog2,aaa,bbb
----------------------
main.cpp
---------------------
#include "mainfrm.h"
#include "dialog1.h"
#include "dialog2.h"
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |