Jump to content

need help with parse error


Gruzin

Recommended Posts

Here is my echo, but think I don't write it right. hope u can help, thanks.

<?php echo '<img alt="" src="'.$imageArr[$imageShow].'">'."".'<a href='".$imageLink[$imageShow]."'>'; ?>

P.S output:

[color=red]Parse error: parse error, unexpected '\"', expecting ',' or ';' in /users/3d_cn/html/banner.php on line 44[/color]
Link to comment
https://forums.phpfreaks.com/topic/15048-need-help-with-parse-error/
Share on other sites

Did that solution work? I can see why yours didn't work in the first place but it is hard to find because of the way you use your quotes.

After your href you drop out of your php string before the double quote goes in. And something similar later on too.

Most importantly, you don't need to drop out of strings to include variables which is what businessman was showing.
His code looks even simpler if you combine your quoting methods so you don't have to escape them:

[code]echo '<img alt="" src="{$imageArr[$imageshow]}"> <a href="{$imagelink[$imageshow]}">';[/code]

or

[code]echo "<img alt='' src='{$imageArr[$imageshow]}'> <a href='{$imagelink[$imageshow]}'>";[/code]

I'm not even certain you need the curly braces either. They are for more complicated structures, so possibly. But if the array index isn't a variable then you don't, so possibly not. Can't check right now for you. Try it:

[code]echo "<img alt='' src='$imageArr[$imageshow]'> <a href='$imagelink[$imageshow]'>";[/code]

Sam.
I tryed but it doesn't work, what's my mistake:(

here is the code:

<?php
$imageArr = array();
$imageArr[1] = "http://www.3d.caucasus.net/apartments/banners/banner1.jpg";
$imageArr[2] = "http://www.3d.caucasus.net/apartments/banners/banner2.jpg";
$imageArr[3] = "http://www.3d.caucasus.net/apartments/banners/banner3.jpg";

$imageLink[1] = "http://www.one.com";
$imageLink[2] = "http://www.two.com";
$imageLink[3] = "http://www.three.com";

$imageShow = array_rand($imageArr);
?>

<?php echo "<img alt='' src='$imageArr[$imageshow]'> <a href='$imagelink[$imageshow]'>"; ?>

P.S Here you can see the site, with that error:
http://www.3d.caucasus.net

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.