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>";

?>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.