Learn to study
 
Aug 29, 2005 - 12:05 PM
 
Main Menu

Online
There are 2 unregistered users and 0 registered users on-line.

You can log-in or register for a user account here.


Our Partners:
PHP Programming: Web Pages With Variable Content
Friday, April 08, 2005 - 07:29 PM

Printer-friendly page Send this story to someone

Website Development

How do I include variable content in a PHP page?

You may have seen on quite a few sites when they link to a file they just link to "www.example-domain.com/?page=pic.html&pic=jane-austin.jpg" or such. The idea is to link to a PHP page that includes the selected picture inside a web page without having to make a separate html file for every single picture, for example.

Unless you need to apply a universal template to the pages, you can simply make this a PHP page that accepts and displays variable content. PHP is a preprocessor, which means it automatically reads the page and executes code it finds. Any variables from a link are automatically brought into existence.

For this example, If you do not need templates to be varied by the image, just create a PHP page with whatever HTML you want on it, then include:

<img src=<?php print $pic; ?> alt="">

Unfortunately, PHP does not have an easy way of getting the height and width of an image so they can be added to the IMG tag. (However, an imaginative programmer might create snippets of JavaScript to peek at the height and width and document.write() them out to the IMG tag. But I'll leave that for the future.

If the page is index.php, you can call it with only the domain name

domain/?$pic=victorian-lady.jpg


or by specifying a directory.

domain/directory/?$pic=victorian-lady.jpg


Note: Reprinted from: http://www.phphelp.com/article/39p3.php




 
Login
 





 Log in Problems?
 New User? Sign Up!

Related links
· More about Website Development
· News by ovlazare


Most-read story in Website Development:
Common PHP Tasks and Questions


Web Pages With Variable Content | Log-in or register a new user account | 0 Comments
Comments are statements made by the person that posted them.
They do not necessarily represent the opinions of the site editor.
© WebsiteDevelopmentNews.com
Flash Templates and Web Templates