DDmUSA Posted February 19, 2011 Share Posted February 19, 2011 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/ Share on other sites More sharing options...
litebearer Posted February 19, 2011 Share Posted February 19, 2011 define 'unsuccessful" be specific as to what is/isn't happening - error messages etc Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1176671 Share on other sites More sharing options...
DDmUSA Posted February 19, 2011 Author Share Posted February 19, 2011 The image map did not appear on the page. I only need one of the href values to come from a file's content within the image map. How would someone code this to happen? Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1176679 Share on other sites More sharing options...
litebearer Posted February 19, 2011 Share Posted February 19, 2011 first run 2 simple tests... 1. try the image map with data hard coded 2. test the content of $file38b Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1176681 Share on other sites More sharing options...
kenrbnsn Posted February 19, 2011 Share Posted February 19, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1176690 Share on other sites More sharing options...
DDmUSA Posted February 20, 2011 Author Share Posted February 20, 2011 Using the suggested code, I do not see the image map. What I see on the page is the following text: "; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; ?> Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1177049 Share on other sites More sharing options...
kenrbnsn Posted February 20, 2011 Share Posted February 20, 2011 If you see that when you do a show source, then the PHP code is not being interpreted. How are you invoking the script? What is the name of the script? Ken Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1177059 Share on other sites More sharing options...
DDmUSA Posted February 20, 2011 Author Share Posted February 20, 2011 The website where I want to include the code is: collegevillediner.com/index2.html I would like to have the code replace the image map that appears on the left sidebar. Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1177060 Share on other sites More sharing options...
kenrbnsn Posted February 20, 2011 Share Posted February 20, 2011 PHP code must be contained in files with the extension ".php" (99% of the time) or the code is not interpreted. Ken Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1177066 Share on other sites More sharing options...
DDmUSA Posted February 20, 2011 Author Share Posted February 20, 2011 Thank you very much for solving the mystery, so to speak..... I now have a working image map. I also appreciate having learning that I can use single ticks within the HTML parameters so I don't have to escape out the double ticks. Quote Link to comment https://forums.phpfreaks.com/topic/228169-changing-an-href-value-based-on-file-contents/#findComment-1177073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.