Jump to content


Photo

PHP and HTML within echo?


  • Please log in to reply
4 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 15 June 2006 - 09:10 AM

I have a list of links on the left of my page which is a combination of HTML and PHP coding. However, everytime I come to create a new page I have to go back to all my other page(s) and add the new link on...

So is it possible to copy the link data and put it into a variable (eg $links) and then echo this on my pages to save me time (also this would mean I only have to update the code once rather than on each page).

I could simply then have include and echo the $link - but can you echo HTML and PHP?

I tried but it never worked, anyone know of a way?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 June 2006 - 09:29 AM

You can create file and called it links.html which will store all your links then where ever you want you links to display you use this code:
<?php include 'links.html'; ?>
And your links will appear where ever you place the include.

Therefore you can just edit the links.html file to edit your links or to add in links and it'll be reflected instantly throughout your site.

#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 15 June 2006 - 11:19 AM

Will this way mean I will have to use frames? or will it just be echo ing as normal?

I'm trying to avoid using frames if possible

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 15 June 2006 - 11:40 AM

No its nothing to do with frames! You dont need to echo anything either with echo! ie:
links.html
<a href="index.php">Home</a><br />
<a href="tutorials.php">Tutorials</a><br />
<a href="porfolio.pgp">Portfolio</a><br />
.. more links here ..
Now in your page you do this:
<?php

//some code here

include 'links.html';

?>
Now when PHP goes to parse your code it'll basically get the contents of links.html and copy 'n' paste it where include was stated

No need for frames or anythink! Just try it out.

#5 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 15 June 2006 - 11:41 AM

Your a star!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users