kate_rose Posted October 5, 2012 Share Posted October 5, 2012 Hi, I have a simple piece of html generated by fireworks to show a graphic with 2 links that looks like this <img name="desert_springs" src="[url="http://cherokee.tosm.ttu.edu/ttunrm/Splash/systems_species_studied/desert_springs.jpg"]http://cherokee.tosm...rt_springs.jpg"[/url] width="230" height="169" border="0" id="desert_springs" usemap="#m_desert_springs" alt="" /><map name="m_desert_springs" id="m_desert_springs"> <area shape="rect" coords="0,40,230,169" href="[url="http://www.myweb.ttu.edu/darogows/research/rogowski_research.html"]http://www.myweb.ttu..._research.html"[/url] title="link to rogowski lab web page (desert springs)" alt="link to rogowski lab web page (desert springs)" /> <area shape="rect" coords="0,0,230,40" href="[url="http://cherokee.tosm.ttu.edu/ttunrm/splash/systems_species_studied/systems.php"]http://cherokee.tosm...ed/systems.php"[/url] title="link to NRM systems we study page" alt="link to NRM systems we study page" /> </map> it works fine when I paste it into my div but I am trying to create an MD array with the names of the graphics as the key and 2 values [0] - a link url and [1] - a bit of text & use array_rand to pull a random graphic name so the content of the div will change on reload of the page A sample of my MD array looks like this (I didn't include the whole thing because its very big $systems = array( "desert_springs" => array( "[url="http://www.myweb.ttu.edu/darogows/research/rogowski_research.html"]http://www.myweb.ttu..._research.html"[/url], "link to rogowski lab web page (desert springs)" ), "ephemeral_waters" => array( "[url="http://myweb.ttu.edu/kerrgrif/Research.htm"]http://myweb.ttu.edu...f/Research.htm"[/url], "link to Griffis-Kyle research lab (ephemeral waters)" ), "systems_agave_weevil" => array( "[url="http://www.rw.ttu.edu/perry/agave_weevil.html"]http://www.rw.ttu.ed...ve_weevil.html"[/url], "link to perry lab research (agave weevil)", ), "systems_amphib_conservation" => array( "[url="http://myweb.ttu.edu/kerrgrif/Research.htm"]http://myweb.ttu.edu...f/Research.htm"[/url], "link to Griffis-Kyle research lab (amphibian conservation)" ), ); So to reproduce basically what I have in the first html code snippet but with a random graphic name I am using this php code $rand_system = array_rand($systems, 1); echo "<img name=\""$rand_system"\" src=\"[url="http://cherokee.tosm.ttu.edu/ttunrm/Splash/systems_species_studied/%22$rand_system%22.jpg\"]http://cherokee.tosm...d_system".jpg\"[/url] id=\""$rand_system"\" usemap=\"#m_"$rand_system"\" alt=\"\" border=\"0\" height=\"169\" width=\"230\"><map name=\"m_"$rand_system"\" id=\"m_"$rand_system"\">"; echo "<area shape=\"rect\" coords=\"0,40,230,169\" href=\"".$systems['$rand_system'][0]"\" title=\"".$systems['$rand_system'][1]"\" alt=\"".$systems[$rand_system][1]"\">"; echo "<area shape=\"rect\" coords=\"0,0,230,40\" href=\"[url="http://cherokee.tosm.ttu.edu/ttunrm/splash/systems_species_studied/systems.php\"]http://cherokee.tosm...d/systems.php\"[/url] title=\"link to NRM systems we study page\" alt=\"link to NRM systems we study page\"> </map>"; But I am getting a syntax error for the 1st two echo statements and I just can't seem to find the problem. Maybe just tired eyes but . . . please help . . . admitedly I am pretty new at this or getting started again after having kids anyway Thanks, Kate Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/ Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 http://us2.php.net/manual/en/language.types.string.php http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.single http://us2.php.net/manual/en/language.types.string.php#language.types.string.syntax.single http://us2.php.net/manual/en/language.types.string.php#language.types.string.parsing http://php.net/manual/en/language.operators.string.php You have some serious issues with your strings, and need to learn how to escape and concatenate strings. Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382897 Share on other sites More sharing options...
darkfreaks Posted October 5, 2012 Share Posted October 5, 2012 (edited) can you post the full error code please also as Jesi just mentioned you are not concatenate your strings properly. Edited October 5, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382899 Share on other sites More sharing options...
kate_rose Posted October 5, 2012 Author Share Posted October 5, 2012 Jessica, I looked at all the links you posted & in fact read them all before I got started on this. I thought I had better not use the single quote variety of string because the html I have has a lot of "s in it. So can you be specific about what issues I have?? An example would be really helpful. Do I need to concatenate in my echo commands every time I let a piece of php peek through?? I didn't think I did. So my understanding is when I use an echo command it goes like this echo "non-php non-php non-php"php php php"non-php non-php non-php" etc. and them I am just using the \ to allow the "s to show through for the html darkfreaks, I am trying to get this code at least apparently error free before putting it up on my server so I don't have the php error to put up. I am using dreamweaver as my code editor and it says I have a syntax error in the 1st 2 echo commands (oddly not the 3rd one though). Thanks, Kate I will go see what errors I am getting in php now that I have access to the server so I can report back Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382907 Share on other sites More sharing options...
Jessica Posted October 5, 2012 Share Posted October 5, 2012 You have unescaped " in your strings. Make it much simpler: echo "Hello my name is "bob""; You see the very obvious problem there, right? Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382910 Share on other sites More sharing options...
darkfreaks Posted October 5, 2012 Share Posted October 5, 2012 (edited) if you do something like echo <<<EOL //code here EOL; you do not really have to put in dots or quotes to escape or concat. just do something like echo <<<EOL my system is $systems. {$systems[$rand_system][1]} EOL; Edited October 5, 2012 by darkfreaks Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382920 Share on other sites More sharing options...
kate_rose Posted October 5, 2012 Author Share Posted October 5, 2012 Jessica, yes I see the error - I will go back through my code - it was late last night so I must have missed a couple (Oh yeah I see one now) darkfreaks I started out using a heredoc but it looked like when I tried to pull a value from the array using .$systems['$rand_system'][0] wasn't working correctly so I skipped back to this Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382931 Share on other sites More sharing options...
darkfreaks Posted October 5, 2012 Share Posted October 5, 2012 Kate: did you escape your array variable with curly braces inside your HEREDOC? it should have output just fine. Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382934 Share on other sites More sharing options...
kate_rose Posted October 5, 2012 Author Share Posted October 5, 2012 Thank you both for the hints. I will go work on this some more and may be back for a follow up. Kate Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382937 Share on other sites More sharing options...
kate_rose Posted October 5, 2012 Author Share Posted October 5, 2012 darkfreaks I think that was my problem - the curly brackets - I just didn't see that info in the heredoc documentation in the php manual when I was reading it I think I will try your solution & report back in a bit kate Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382939 Share on other sites More sharing options...
kate_rose Posted October 5, 2012 Author Share Posted October 5, 2012 Horray!! It worked - thank you both for your help and patience I am sure I will be back as I run into more things with easy solutions that I have to relearn Kate Quote Link to comment https://forums.phpfreaks.com/topic/269121-echo-syntax-error-generating-html-code-with-php-bits-subed-in/#findComment-1382952 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.