473,666 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a more efficient way to do this?

Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the shell
changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?

Thanks, - Dave

Aug 15 '06 #1
20 1750
la***********@z ipmail.com wrote:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the shell
changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?

Thanks, - Dave
Get the file contents with file_get_conten ts(), then pluck out the body
with a regular expression. Something like:

$s = file_get_conten ts("bobo.html") ;
preg_match("/<\s*body.*?>(.* ?)<\/\s*body.*?>/is", $s, $m);
$body = $m[1];

Aug 15 '06 #2
Rik
la***********@z ipmail.com wrote:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the
shell changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?

well, first of all I really urge you to forget tables for layout and to use
css. Tables are for tabular data only.

with that out of the way:

---head.html----------
<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td>
----------------------
---foot.html----------
</td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>
----------------------
--page.php------------
include('head.h tml');
/* generate content */
include('foot.h tml');
----------------------

Alternatively, you could get ALL your static HTML in these two files, andf
all pages which need it are in the same dir: echo only the content in the
*.php pages, and create an .htaccess:

--.htaccess------------
php_flag auto_prepend_fi le head.html
php_flag auto_append_fil e foot.html
-----------------------
---page.php------------
echo $content;
-----------------------

Grtz,
--
Rik Wasmus
Aug 15 '06 #3
la***********@z ipmail.com wrote:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the shell
changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?

Thanks, - Dave
Or, you don't even need php - you can do a server-side include, if your
server is set up to parse the file for SSI:

<!--#include virtual="/file/contains/mystuff.html" -->

Slightly more efficient than using PHP if you're already parsing the
file for SSI (the server will handle it without calling PHP). But
probably less efficient if you aren't already parsing it.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 15 '06 #4
--.htaccess------------
php_flag auto_prepend_fi le head.html
php_flag auto_append_fil e foot.html
-----------------------
---page.php------------
echo $content;
-----------------------
Regarding this idea, will the prepend happen at the very beginning of
the page? I still want each of my 15 pages to have custom titles (e.g.
the <TITLEelement is different for each) and I wouldn't want to screw
up the HTML by prepending data before the "<HTML><HEAD><T ITLE>..."
elements.

Anyway, great ideas.

Thanks, -
Rik wrote:
la***********@z ipmail.com wrote:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the
shell changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?


well, first of all I really urge you to forget tables for layout and to use
css. Tables are for tabular data only.

with that out of the way:

---head.html----------
<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td>
----------------------
---foot.html----------
</td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>
----------------------
--page.php------------
include('head.h tml');
/* generate content */
include('foot.h tml');
----------------------

Alternatively, you could get ALL your static HTML in these two files, andf
all pages which need it are in the same dir: echo only the content in the
*.php pages, and create an .htaccess:

--.htaccess------------
php_flag auto_prepend_fi le head.html
php_flag auto_append_fil e foot.html
-----------------------
---page.php------------
echo $content;
-----------------------

Grtz,
--
Rik Wasmus
Aug 15 '06 #5
Or, you can change all 15 pages to one php page, which includes the body
contents from one of 15 html files.
This would change a typical url from "yourdomain .com/page3.php" to
"yourdomain .com/main.php?page3" , and the php script would have a line like
<td><?php include ($root . "/" . $query . ".html"); ?></td>
For the title, just echo a variable $title which gets looked up based on
the query string.

Note this has other repercussions like affecting search engine behaviour
and caching, so it may not be the ideal solution.

"la***********@ zipmail.com" wrote:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the
content of the BODY and put it in a little table ...

<table>
<tr><td colspan="3"><im g src="header.gif "></td></tr>
<tr>
<td><img src="left_img.g if"></td>
<td><!-- body content goes here --></td>
<td><img src="right_img. gif"></td>
</tr>
<tr><td colspan="3"><im g src="bottom.gif "></td></tr>
</table>

It is a pain to have to cut and paste all this HTML code (the above is
just an abbreviated version) into all 15 pages. And plus, if the shell
changes, I'll have to change it in 15 pages. Any advice on an
efficient way to add this to everything?

Thanks, - Dave
Aug 15 '06 #6
Rik
la***********@z ipmail.com wrote:
>--.htaccess------------
php_flag auto_prepend_fi le head.html
php_flag auto_append_fil e foot.html
-----------------------
---page.php------------
echo $content;
-----------------------

Regarding this idea, will the prepend happen at the very beginning of
the page?
Yes, before line 0 so to speak.
I still want each of my 15 pages to have custom titles
(e.g.
the <TITLEelement is different for each) and I wouldn't want to
screw
up the HTML by prepending data before the "<HTML><HEAD><T ITLE>..."
elements.
Either check & set the title in the head.php (instead of a static *.html),
or go with Gary Hasler's option (which is the one I normally use). The
drawbacks he mentions can easily be solved.

I usually use some RewriteRule's in .htaccess to make it seems they're
different static pages.

Grtz,
--
Rik Wasmus
Aug 15 '06 #7
Rik wrote:
I usually use some RewriteRule's in .htaccess to make it seems they're
different static pages.
That's the ultimate solution--then the clients never even need know there's
any php involved. I'd love to have most of our site done like that but
unfortunately rewrite's not available on our current hosted server.

Aug 15 '06 #8
Rik wrote:
--page.php------------
include('head.h tml');
/* generate content */
include('foot.h tml');
----------------------
Agh! Drives me crazy that people keep recommending this hamfisted
method. Doing includes in lieu of calling function is a poor way to
program. A page header or footer is not different from other
functionalities in your application. To reuse it, wrap it in a
function. Example:

--interface.php---

<?php function printHeader() { ?>
<html><head>. ..
<?php } ?>

<?php function printFooter() { ?>
....</body></html>
<?php } ?>
-----------------------

Note the immediate advantage here of having the HTML within the same
file. It's also obvious how you would implement any parameterized
behavior--by passing parameters. To handle different page title, for
example:

<?php function printHeader($ti tle = "Home Page") { ?>
<html><head>
<title><?php echo htmlspecialchar s($title); ?></title>
<?php } ?>

The individual pages then pass their own titles when they need to
override the default.

Aug 15 '06 #9
Rik
Chung Leong wrote:
Rik wrote:
>--page.php------------
include('head. html');
/* generate content */
include('foot. html');
----------------------

Agh! Drives me crazy that people keep recommending this hamfisted
method. Doing includes in lieu of calling function is a poor way to
program. A page header or footer is not different from other
functionalities in your application. To reuse it,
Pardon, 'reuse'? How many heads/closing html tags do you want in a page? I
normally opt for just one, but hey, that's silly me.
wrap it in a
function. Example:

--interface.php---

<?php function printHeader() { ?>
<html><head>. ..
<?php } ?>

<?php function printFooter() { ?>
...</body></html>
<?php } ?>
-----------------------

Note the immediate advantage here of having the HTML within the same
file. It's also obvious how you would implement any parameterized
behavior--by passing parameters. To handle different page title, for
example:

<?php function printHeader($ti tle = "Home Page") { ?>
<html><head>
<title><?php echo htmlspecialchar s($title); ?></title>
<?php } ?>

The individual pages then pass their own titles when they need to
override the default.
Well, that's indeed a pro to the include.
However, a con is this: If I want to change something in the head once the
project is running, I usually don't want to fiddle around in files anymore,
I want to be able to change it in an interface. While a *.php page can just
be opened and displayed in an textarea, I'm definitely more at ease working
on the plain HTML bits.

Then again, my bigger projects all have a dynamically built head section,
little to no actual static HTML content there.

Grtz,
--
Rik Wasmus
Aug 15 '06 #10

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

Similar topics

6
2653
by: Narendra C. Tulpule | last post by:
Hi, if you know the Python internals, here is a newbie question for you. If I have a list with 100 elements, each element being a long string, is it more efficient to maintain it as a dictionary (with a key = a string from the list and value = None) for the purpose of insertion and removal? Basically, if Python really implements lists as linked lists but dictionaries as hash tables, it may well be that hashing a key takes negligible time...
3
1557
by: sandeep | last post by:
Hi i am new to this group and to c++ also though i have the knowledge of "c" and now want to learn c++ and data structure using c/c++ . so could nebody please suggest me some tips(books,links,&experiences) so that i can be an EFFICIENT programmer of c++. Also i want to ask that how can we develope efficient codes and what are various techniques for writing code sin efficient manner. Please help me.
2
8481
by: Vance M. Allen | last post by:
Greetings, I am establishing a database for the purpose of logging access to my secure webserver and am wanting to make the database as efficient as I can because it will be doing a lot of work when the site goes live. What is the most efficient way in a MySQL table to store remote IP addresses? What data type should I use? Should I just go with a basic VARCHAR(15) to allow for 4 sets of 3 digits with 3 decimal separators, or is...
15
2325
by: Tor Erik Sønvisen | last post by:
Hi I need a time and space efficient way of storing up to 6 million bits. Time efficency is more important then space efficency as I'm going to do searches through the bit-set. regards tores
2
1728
by: SR | last post by:
Hi, I was wondering if there any good books or articles on efficient programming in C to achieve reductions in computation time(especially in parallel environments) etc. Pointers to any books or articles would be helpful. Thanks
10
1967
by: Teis Draiby | last post by:
In an application manipulating streaming video and 3D stuff I want to implement mutithreading to ensure a decent UI response time. Since my application is very speed critical I want to use the most efficient synchronization of the shared data objects. What would that be in this case? I think there's a very simple answer to this, but I am somewhat confused by the different methods available. The data I need to transfer between threads...
3
6418
by: Brian Wotherspoon | last post by:
I have a table with data that is refreshed regularly but I still need to store the old data. I have created a seperate table with a foreign key to the table and the date on which it was replaced. I'm looking for an efficient way to select only the active data. Currently I use: SELECT ... FROM DataTable AS D LEFT OUTER JOIN InactiveTable AS I ON I.Key = D.Key
16
1673
by: Dustan | last post by:
I have a program that uses up a lot of CPU and want to make it is efficient as possible with what I have to work with it. So which of the following would be more efficient, knowing that l is a list and size is a number? l=l del l If it makes a difference, everything in the list is mutable.
5
2580
by: Alan Little | last post by:
I have affiliates submitting batches of anywhere from 10 to several hundred orders. Each order in the batch must include an order ID, originated by the affiliate, which must be unique across all orders in all batches ever submitted by that affiliate. I'm trying to figure out the most efficient way to check the uniqueness of the order ID. Order data is being submitted to Zen Cart, and also stored in custom tables. I have created a unique...
25
15547
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that true? regards, ...ab
0
8356
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,...
0
8781
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
8551
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,...
0
8640
tracyyun
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...
0
7386
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
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
4198
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...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
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...

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.