Jump to content

help please: unexpected T_ENCAPSED_AND_WHITESPACE


The14thGOD

Recommended Posts

I keep getting this error but i can't figure out why, I believe it is this code:

<?php
				while($row = mysql_fetch_array($results)) {
					$row['image'] = str_replace("../","",$row['image']);
					$row['body'] = str_replace("\r\n","<br /><br />",$row['body']);
					$row['body'] = str_replace("\n","<br /><br />",$row['body']);
					echo("<h3>$row['headline']</h3>");
					echo("<img src=\"$row['image']\" width=\"334\" height=\"184\" />");
					echo("<p>$row['body']</p><br />");
				}
			?>

when i take it out it doesn't do it anymore

 

help asap please :)

 

thanks

while($row = mysql_fetch_array($results))

{

$row['image'] = str_replace("../","",$row['image']);

$row['body'] = str_replace("\r\n","<br /><br />",$row['body']);

$row['body'] = str_replace("\n","<br /><br />",$row['body']);

echo"<h3>".$row['headline']."</h3>";

echo"<img src=\"".$row['image']."\" width=\"334\" height=\"184\" />";

echo"<p>".$row['body']."</p><br />";

}

 

that will work

The problem is when you use array elements (like $row['image']) inside a double-quoted string.  You need to "protect" them from misinterpretation like this:

 

print "The image is $row['image']"; # WRONG, will give error
print "The image is {$row['image']}\n"; # RIGHT, no error

 

teng84's method also works (he is using "." to stick strings together with variables).

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.