473,800 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Embedding php in html code?

Hi All,

I'm a new boy to php and working on a web site with long sections of
code that could be done as includes apart from one or two things
changing.
I've tested the following and it works, but what I really want to know
is am I OK placing php code inside a html line like this, or could there
be problems?
<!-- html code for test.php -->
<!-- lot of code cut -->
<a href="<?php print $filename; ?>"><?php print $title; ?></a>
<!-- lot of code cut -->
<!-- end of test.php -->

<!-- which is called in the main file like this -->
<?php
$filename="inde x.php";
$title="Index Page";
include ("test.php") ;
?>

--
Ken Ward in Norwich ke*@oldcity.f2s .com
For Norwich and East Anglia visit www.oldcity.org.uk
Jul 17 '05 #1
10 2135
Ken Ward wrote:
Hi All,

I'm a new boy to php and working on a web site with long sections of
code that could be done as includes apart from one or two things
changing.
I've tested the following and it works, but what I really want to know
is am I OK placing php code inside a html line like this, or could there
be problems?
<!-- html code for test.php -->
<!-- lot of code cut -->
<a href="<?php print $filename; ?>"><?php print $title; ?></a>
<!-- lot of code cut -->
<!-- end of test.php -->

<!-- which is called in the main file like this -->
<?php
$filename="inde x.php";
$title="Index Page";
include ("test.php") ;
?>


Yeah I guess you're ok. You can actually use a shorter syntax to just print
a variable: <?= $varname ?>

I suspect someone will suggest you use some kind of template system that
separates your PHP from your HTML. Well, they have a lot of time on their
hands :)

..:A

--
http://www.ninja.up.ac.za
Jul 17 '05 #2
..:Ninja wrote:
Yeah I guess you're ok. You can actually use a shorter syntax to just
print a variable: <?= $varname ?>


This, however, will only work if the PHP directive "short_open_tag " is
se to On, and by default many hosts have it off.

--
Suni

Jul 17 '05 #3
In message <10************ ***@inet2.up.ac .za>, ".:Ninja"
<al**@it.up.ac. za> writes
Ken Ward wrote:
Hi All,

I'm a new boy to php and working on a web site with long sections of
code that could be done as includes apart from one or two things
changing.
I've tested the following and it works, but what I really want to know
is am I OK placing php code inside a html line like this, or could there
be problems?
<!-- html code for test.php -->
<!-- lot of code cut -->
<a href="<?php print $filename; ?>"><?php print $title; ?></a>
<!-- lot of code cut -->
<!-- end of test.php -->

<!-- which is called in the main file like this -->
<?php
$filename="inde x.php";
$title="Index Page";
include ("test.php") ;
?>
Yeah I guess you're ok. You can actually use a shorter syntax to just print
a variable: <?= $varname ?>

I suspect someone will suggest you use some kind of template system that
separates your PHP from your HTML. Well, they have a lot of time on their
hands :)


Takes more time initially but probably saves it in the long term.
.:A


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #4

".:Ninja" <al**@it.up.ac. za> wrote in message
news:10******** *******@inet2.u p.ac.za...
I suspect someone will suggest you use some kind of template system that
separates your PHP from your HTML. Well, they have a lot of time on their
hands :)


Oi! ;-)

Garp
Jul 17 '05 #5
"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:Ev******** ******@[127.0.0.1]...
I suspect someone will suggest you use some kind of template system that
separates your PHP from your HTML. Well, they have a lot of time on their
hands :)


Takes more time initially but probably saves it in the long term.


I doubt it. Using a template system is a little like going back to using PHP
1--you get a far less powerful, less flexible system to work with.

I'm not saying that template systems are bad. People just need to remember
that their raison d'etre is to limit what can be done within a page. If that
is your requirment then it makes sense. Otherwise it can hardly be
advisable. The benefits of "separating presentation from logic" is abstract
and often times cosmetic, whereas the impact of bumping into a template
system limitation is very real.
Jul 17 '05 #6
In message <qo************ ********@comcas t.com>, Chung Leong
<ch***********@ hotmail.com> writes
"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:Ev******* *******@[127.0.0.1]...
>I suspect someone will suggest you use some kind of template system that
>separates your PHP from your HTML. Well, they have a lot of time on their
>hands :)
Takes more time initially but probably saves it in the long term.


I doubt it. Using a template system is a little like going back to using PHP
1--you get a far less powerful, less flexible system to work with.

I'm not saying that template systems are bad. People just need to remember
that their raison d'etre is to limit what can be done within a page. If that
is your requirment then it makes sense. Otherwise it can hardly be
advisable. The benefits of "separating presentation from logic" is abstract
and often times cosmetic, whereas the impact of bumping into a template
system limitation is very real.


I would have said the reason for using a template (in the way I mean it)
is to make it easy to get a uniform page layout across a site.


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #7

"Chung Leong" <ch***********@ hotmail.com> wrote in message
news:qo******** ************@co mcast.com...
"Five Cats" <ca*******@[127.0.0.1]> wrote in message
news:Ev******** ******@[127.0.0.1]...
I suspect someone will suggest you use some kind of template system thatseparates your PHP from your HTML. Well, they have a lot of time on theirhands :)
Takes more time initially but probably saves it in the long term.


I doubt it. Using a template system is a little like going back to using

PHP 1--you get a far less powerful, less flexible system to work with.
I totally disagree. My system is based around an amalgamation of the 3 tier
architecture (refer to
http://www.tonymarston.co.uk/php-mys...structure.html) and the
Model-View-Controller design pattern (refer to
http://www.tonymarston.co.uk/php-mys...ontroller.html) and it
has proved to be very powerful and very flexible.
I'm not saying that template systems are bad. People just need to remember
that their raison d'etre is to limit what can be done within a page. If that is your requirment then it makes sense. Otherwise it can hardly be
advisable. The benefits of "separating presentation from logic" is abstract and often times cosmetic, whereas the impact of bumping into a template
system limitation is very real.


I use XSL stylesheets to generate all my HTML and I have never found any
limitations. In fact my level of reusable code has gone up considerably
since using XSL. Take a look at
http://www.tonymarston.co.uk/xml-xsl/reusable-xsl.html for details.

--
Tony Marston

http://www.tonymarston.net

Jul 17 '05 #8
Chung Leong wrote:
I'm not saying that template systems are bad. People just need to
remember that their raison d'etre is to limit what can be done within
a page. If that is your requirment then it makes sense.


Than it always makes sense. You see, you *must* limit what happens in a
page; specifically, the only thing that happens in a page is what is needed
to display it.

Everything else: database queries, calculations, text translations etc
should be done separately. When it comes to HTML, all data should already be
prepared for display. This is why templates are a good tool, despite their
performance penalty.

Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.
Jul 17 '05 #9

"Berislav Lopac" <be************ @dimedia.hr> wrote in message
news:c7******** **@ls219.htnet. hr...
Chung Leong wrote:
I'm not saying that template systems are bad. People just need to
remember that their raison d'etre is to limit what can be done within
a page. If that is your requirment then it makes sense.
Than it always makes sense. You see, you *must* limit what happens in a
page; specifically, the only thing that happens in a page is what is

needed to display it.
I disagree with your emphasis on *must*. It is possible to write a component
which contains presentation, business and data access logic, but this does
not offer much opportunity for reusability. Personally I use a combination
of the 3 tier architecture and the Model-View-Controller design model to
produce a great deal of reusable code. However, the design and
implementation of such an infrastructure is beyond the capabilities of most
developers.
Everything else: database queries, calculations, text translations etc
should be done separately. When it comes to HTML, all data should already be prepared for display. This is why templates are a good tool, despite their
performance penalty.
All my HTML is produced from XML data using XSL stylesheets. There may be a
performance overhead but the savings are made in short development times and
large amounts of reusable code.

--
Tony Marston

http://www.tonymarston.net
Berislav

--
If the Internet is a Marx Brothers movie, and Web, e-mail, and IRC are
Groucho, Chico, and Harpo, then Usenet is Zeppo.

Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1854
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to explain it in details, 1. Python initialization and finalization is done in the *main* thread. 2. For each new thread I create a separate sub-interpreter . 3. Using PyRun_String("import myModule"...) before execution of python
4
2791
by: Alicia Haumann | last post by:
I accidentally sent this to webmaster@python.org, so this could be a duplicate if "webmaster" forwards it to this list. :{ Hi, there. Thanks for any help that can be offered. I've been working with Python for a year or more now, but only doing simple extending in C/C++. I'm now attempting some embedding and several questions have come to mind. BTW - I'm running Windows 2000 with Python23 and VisualC++ developers
2
2873
by: Roose | last post by:
With some googling I have found these resources: http://docs.python.org/ext/win-dlls.html http://www.python.org/doc/faq/windows.html I have a large Win32/MFC/C/C++ application that has an embedded scripting language (a very limited one). I would like to rip it out and replace it with Python. I am thinking that this would be relatively simple since the scripting language is a very small interface between the UI and the engine --...
56
6975
by: alan b | last post by:
I copied it and tried to edit the movie.htm below in the <PARAM NAME=*** location of the file where the videoclip is on my hard drive. It is already recorded by Windows Media Player. My version is 9.0 although it is coded 5.0 in this htm file. Let me know if it is able to be fixed. *** denotes where it is edited to locate the path where the videoclip is.
8
1799
by: Alan Lue | last post by:
Hi, I'm trying to set up a webpage so that I can view multiple HTML files from the same page. For example, you might go to http://example.com/lab_tests.html and be able to view lab1.html, lab2.html, and lab3.html right on that page. If you're viewing this message w/a monospace font, the page layout might look like this: +-------------------+ | Header | * Code for Header and
2
1992
by: John Dean | last post by:
Hi Could somebody, please tell me where I can find information about embedding Python into a C/C++ application. The example in the docs is rather simple. I am looking for something a bit more complex and longer -- Best Regards John
6
3011
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python interface is providing a convenient scripting toolkit for the application. One example is that a user can write a python script like: player = Player() game.loadPlayer(player) player.moveTo(location)
4
5699
by: David Abrahams | last post by:
I'm seeing highly surprising (and different!) behaviors of PyImport_ImportModule on Linux and Windows when used in a program with python embedding. On Linux, when attempting to import a module xxx that's in the current directory, I get ImportError: No module named xxx I can work around the problem by setting
6
465
by: mistabean | last post by:
Hello, first of all, I am a programming newbie, especially in python... Onwards to the problem, I have been having difficulty embedding a python module into my C/C++ program. (just a test program before moving on into the real thing). I have been making test runs using the codes from http://docs.python.org/ext/pure-embedding.html as a basic, but modifiying it now as a function inside my C/C++ code.
2
4076
by: John Grandy | last post by:
I am not having success embedding carriage return and line feed characters into a string and displaying them with an ASP.NET label. Is anyone getting either of the following to work ? StringBuilder message = new StringBuilder(); message.Append("Line 1"); message.Append("\r\n"); message.Append("Line 2"); Label.Text = message.ToString();
0
9690
marktang
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...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10275
jinu1996
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...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
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...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.