Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

PHP and HTML within echo?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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:
[code]<?php include 'links.html'; ?>[/code]
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.

Share this post


Link to post
Share on other sites
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

Share this post


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

//some code here

include 'links.html';

?>[/code]
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.