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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.