Jump to content

Changing an HREF value based on file contents


DDmUSA

Recommended Posts

Hello,

 

I have a form that ends up creating a file.  The file has one of two values in the file:

specials.php

specials8.php

 

Within several of my web pages, I have an image map, and I would like one of the href values to be the value that PHP would get from the underlying file.

 

How would I code this to make the image map function accordingly?

 

Notice the "Daily Specials" entry within the image map.  It is this href that I need to become the value from the file.

 

The unsuccessful code that I tried is:

 

<?php

$file38a = "test/activate.txt";

$file38b = file_get_contents("$file38a");

echo "<img src=\"sample2/sidebar1.jpg\" alt=\"Collegeville Diner\" width=\"94\" height=\"330\" border=\"0\" align=\"top\" usemap=\"#Map2\" longdesc=\"http://collegevillediner.com\" />";

echo "<map name=\"Map2\" id=\"Map2\">";

echo "<area shape=\"rect\" coords=\"8,102,88,152\" href=\"about.htm\" target=\"_self\" alt=\"About the Diner\" />";

echo "<area shape=\"rect\" coords=\"7,159,90,204\" href=\"menu.htm\" target=\"_self\" alt=\"Our Menu\" />";

echo "<area shape=\"rect\" coords=\"7,214,90,262\" href=\"$file38b\" target=\"_self\" alt=\"Daily Specials\" />;

<area shape=\"rect\" coords=\"0,275,86,320\" href=\"desserts.htm\" target=\"_self\" />";

echo "</map>";

?>

 

 

If you do a "show source" after invoking the script, does the source code look like what you wanted?

 

Try this:

<?php
$file38b = trim(file_get_contents('test/activate.txt'));
echo "<img src='sample2/sidebar1.jpg' alt='Collegeville Diner' width='94' height='330' border='0' align='top' usemap='#Map2' longdesc='http://collegevillediner.com' />";
echo "<map name='Map2' id='Map2'>";
echo "<area shape='rect' coords='8,102,88,152' href='about.htm' target='_self' alt='About the Diner' />";
echo "<area shape='rect' coords='7,159,90,204' href='menu.htm' target='_self' alt='Our Menu' />";
echo "<area shape='rect' coords='7,214,90,262' href='$file38b' target='_self' alt='Daily Specials' />";
echo "<area shape='rect' coords='0,275,86,320' href='desserts.htm' target='_self' />";
echo "</map>";
?>

 

Ken

Archived

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

×
×
  • Create New...

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.