Jump to content

"echo" Syntax Error Generating Html Code With Php Bits Subed In


kate_rose

Recommended Posts

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

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

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;

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

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

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.