The14thGOD Posted June 29, 2007 Share Posted June 29, 2007 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 https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 Try wrapping the variables in brackets ({}). I don't know what else it would be. Link to comment https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/#findComment-285478 Share on other sites More sharing options...
teng84 Posted June 29, 2007 Share Posted June 29, 2007 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 https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/#findComment-285480 Share on other sites More sharing options...
The14thGOD Posted June 29, 2007 Author Share Posted June 29, 2007 yep,the second method worked, though im confused because I have never had to do that before and it works on my site....if possible would you mind explaining what exactly that does? thank you for the help Link to comment https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/#findComment-285483 Share on other sites More sharing options...
btherl Posted June 29, 2007 Share Posted June 29, 2007 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 https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/#findComment-285488 Share on other sites More sharing options...
The14thGOD Posted June 29, 2007 Author Share Posted June 29, 2007 ah alright, I think I understand now. Thank you. Link to comment https://forums.phpfreaks.com/topic/57657-help-please-unexpected-t_encapsed_and_whitespace/#findComment-285492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.