Forum Moderators: coopster

Message Too Old, No Replies

Help! Newbie wants to incorporate PHP into html

         

buckmajor

11:11 am on May 19, 2008 (gmt 0)

10+ Year Member



Hi there

I have tried so hard to learn PHP and still haven't knuckled it down yet.

I've learnt that PHP can only be generated by a server and process the code to HTML.

I want to set up a website with PHP but don't know how to go about it.

Read so many articles but still can't get my head around it.

Can someone please tell me how it works like if I wanted to include a header, menu and footer into the html page or set up a template so that I don't have to create my own html pages and reload those pages again. Which I heard that PHP doesn't have to reload the banner and footer again.

Hope I've this correctly lol.

Many thanks in advance

CHEERS :)

dreamcatcher

11:30 am on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Related threads in our library:

One Line Template Engine
[webmasterworld.com...]

Learning PHP
[webmasterworld.com...]

dc

jatar_k

11:52 am on May 19, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



or this one

A dynamic site in 2 minutes [webmasterworld.com]

Rosalind

1:33 pm on May 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try to get a good understanding of security before you put anything live. In particular, understand what it means to clean data before you make queries to the database.

Don't expect to learn PHP easily from online articles, especially if it's your first experience of a server-side language. It takes time.

buckmajor

2:32 am on May 22, 2008 (gmt 0)

10+ Year Member



I have a few books and e-books now so hopefully can understand it a lot more.

Thank you everyone those links they were very useful. A dynamic site in 2 minutes is what I was looking for. Just have to put it to practice now lol.

CHEERS :)

chorny

5:24 pm on May 22, 2008 (gmt 0)

10+ Year Member



Use real template engine like Smarty - don't start with bad practice.

dreamcatcher

6:01 pm on May 22, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And also make sure that the tutorials aren`t out of date. You should code everything for PHP5, so ignore PHP4 tutorials. Smarty can be very complicated for a beginner. Might be best to grasp the basics first. A template engine might not be a route you need to go down.

dc

buckmajor

2:13 am on May 23, 2008 (gmt 0)

10+ Year Member



Hey guys

I actually got this include PHP thing working well sort of.

A few errors occured by not showing the page but this code beneath:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /hsphere/local/home/digitalp/example.com/about1.php on line 16

Does anyone know what to do here?

[edited by: dreamcatcher at 6:53 am (utc) on May 23, 2008]
[edit reason] Exemplified url. [/edit]

russkern

4:25 am on May 23, 2008 (gmt 0)

10+ Year Member



What does line 16 and a couple lines above and below look like?

buckmajor

5:04 am on May 23, 2008 (gmt 0)

10+ Year Member



Hi Russkern

Here is the link

<snip>

Code:

<?php
$title='About';

include('includes/header1.php');

echo '
<div id="content">
<h2>About us</h2>
<div id="contentleft" class="orange">

<p>The Bowen Terrace provides fun and friendly, yet quiet and affordable accommodation for travellers from all over the world.
Family owned and operated, The Bowen Terrace will provide you with that "home away from home" feel; a warm and hospitable atmosphere.</p>

<p>The house itself is what is commonly referred to in Australia as a <a href="http://www.google.com" target="_blank">Google</a>.
With it's timber construction, corrugated iron roofing, front and back
verandahs, and traditional architecture, you'll experience a part of the
typical <a href="http://www.google.com" target="_blank">Google</a>
lifestyle.</p>

<p>When you're relaxing out on the back deck on a warm summer's evening, drinking an <a href="http://www.google.com" target="_blank">Google</a>, listening to the mangos drop from the tree onto the roof, you'll see just how laid-back this city can be.
But then notice why the locals refer to the city as "Bris Vegas" as the city lights illuminate the beautiful <a href="http://www.google.com" target="_blank">Google</a> skyline.
But don't worry, you're only a hop-skip-and-a-jump away from the <a href="http://www.google.com" target="_blank">Google</a>.<br />
<br />
Nice</p>

<h3>Links / Reviews</h3>
<ul>
<li><A HREF="http://www.example.com" target="_blank">Test</A></li>
<li><A HREF="http://www.example.com" target="_blank">Test</A></li>
</ul>
</div>

<div id="contentright">
<img src="img/photo-family.jpg" width="200" /></div>
</div>
';

include('includes/footer1.php');

?>

This code works on index1.php

Code:

<?php
$title='Home';

include('includes/header1.php');

echo '
<div id="content">
<h2>Our home page</h2>
<div id="contentleft">
<img src="img/photo-front-normal.jpg" width="420" /></div>
<div id="contentright">

<div id="home">
<ul>
<li>Single or share rooms</li>
<li>Double rooms with fridge, TV, with or without bathrooms</li>
<li>Residents lounge and BBQ deck</li>
<li>Cooking and laundry facilities</li>
<li>100 metres to theatre, coffee shops, and restaurants</li>
<li>Public transport at the door</li>
<li>Shuttle bus service — discount rates.</li>
</ul>
</div>
</div>
</div>
';

include('includes/footer1.php');

?>

So what am I doing wrong?

[edited by: dreamcatcher at 6:53 am (utc) on May 23, 2008]
[edit reason] No urls please! [/edit]

russkern

10:43 am on May 23, 2008 (gmt 0)

10+ Year Member



That echo statement is really too long... with a section that long you should do multiple echo's.

PLus, there is a Semicolon in he middle that may be throwing it off... try this:

<?php
$title='About';
include('includes/header1.php');
?>

Insert all your regular HTML here- without the Echo's

<?php
include('includes/footer1.php');
?>

buckmajor

12:42 am on May 24, 2008 (gmt 0)

10+ Year Member



Thanks Russkern

I will give that one a try and get back to you with the result.

buckmajor

7:41 am on May 26, 2008 (gmt 0)

10+ Year Member



Thanks Russkern

Eureka! That PHP code works.
I just found out that the echo syntax doesn't hold all html tags in its body lol.
Much appreacited.

CHEERS :)

russkern

12:29 pm on May 27, 2008 (gmt 0)

10+ Year Member



Cool... glad to help....

The echo syntax doesn't like long strings like you have (had). it is better to break them up... plus all the double quotes inside your echo statement were likely tripping you up as well... I leave them out. ie.
echo '<img src=img/photo-front-normal.jpg width=420 />';

R

g1smd

7:51 pm on May 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you do that you are probably generating non-valid HTML code.

System

3:54 am on May 28, 2008 (gmt 0)

redhat



The following message was cut out to new thread by jatar_k. New thread at: php/3660517.htm [webmasterworld.com]
12:04 am on May 28, 2008 (est -4)

Marcia

12:57 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?php
if (file_exists("{$filename}.inc.php"))
{include ("{$filename}.inc.php"); }
else
{print "The file requested does not exist."; }
?>

thecoalman

2:59 pm on May 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Two things I'll add to what russkern posted, use $_SERVER['DOCUMENT_ROOT'] in your includes, they'll work in any include or require you use no matter what directory the script is in that is calling them. You can also use the php within the HTML.

<?php
$title='About';
include($_SERVER['DOCUMENT_ROOT'] . 'includes/header1.php');
?>

<h1><?php echo $title ?></h1>
Insert all your regular HTML here- without the Echo's

<?php
include($_SERVER['DOCUMENT_ROOT'] . 'includes/footer1.php');
?>

A quick explanation, $_SERVER['DOCUMENT_ROOT'] is a variable set by the server it should be pointing to the root of your public html folder. The period after $_SERVER['DOCUMENT_ROOT'] appends includes/footer1.php to it.

buckmajor

4:46 am on Jun 5, 2008 (gmt 0)

10+ Year Member



Oh man, this is awesome but a little bit complex for me lol.
I have a question to ask, is there a php template similar to dreamweaver? Now I have a bit of understanding of PHP, so the echo it not good to use for whole lot of html code.

Many thanks in advance
CHEERS :)