Graphic Design shadow to enhance presentation of images.
Graphic Design shadow to enhance presentation of images.

Web Design - Tips, Tricks and Programmng

Using PHP to size a <div> or <table> tag in real time

Return to Forum Home Page

Forum

Return to Topic

Return to Topic

Login to Forum

Login to Forum

Register to access Forum

Register to access Forum

Previous Thread Return to Topic Next Thread
Author Message

Norm Jurgen

Norm Jurgen

Date Joined:
Jan 19, 2010

Posts:
56

Posted: Mon Feb 1, 2010 09:05 PM

Subject: Using PHP to size a <div> or <table> tag in real time

Have you ever want to size a TABLE or DIV statement based upon the dimensions of an image? Using PHP this can be a relatively simple yet powerful task. Here's how...

// Define a variable to record the true source of the image(s) as found on the hosting server.
$source_image = $_SERVER['DOCUMENT_ROOT'] . '/images/';

// Append the source of the image to the image name. Define the image name prior to writing code
// or substitute with a real image name.
$filewpath = $source_image . $image;

// Calculate the width and height of the image and store in appropriately named variables.
list($width, $height) = getimagesize($filewpath);

// Define a style sheet based upon the width of the image.
$html_snippet.= '<style type="text/css">div.supporting-image {
float: left;
margin: 0 0 10px 10px;
padding: 0 0 0 0;
width: ' . $width . ';
} </style>';

// Define a variable to make note of all dynamically generated HTML code.
$html_snippet = '';

// Begin the <div> statement using the style sheet we defined earlier.
$html_snippet.= '<div class="supporting-image">';

// Place all of your HTML code here appending to the $html_snippet variable.

// Within your HTML content make sure you output the value of $html_snippet and close using </div>.

Return to Forum Home Page

Forum

Return to Topic

Return to Topic

Login to Forum

Login to Forum

Register to access Forum

Register to access Forum