Freedom-n-Democrazy Posted October 1, 2011 Share Posted October 1, 2011 I'm getting: unexpected T_ENCAPSED_AND_WHITESPACE Bull shit! Where?! echo "<B>Brand:</B> $row['brand']"; Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
Drummin Posted October 1, 2011 Share Posted October 1, 2011 echo "<B>Brand:</B> $row[brand]"; Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274588 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 1, 2011 Author Share Posted October 1, 2011 What the hell. It worked! Why? ... and thanks man! Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274589 Share on other sites More sharing options...
trq Posted October 1, 2011 Share Posted October 1, 2011 You where missing the concatenation operator which joins strings. Is VERY rare that the language is at fault and not the user. Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274596 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 1, 2011 Author Share Posted October 1, 2011 Why does it require them here then? if ($row['sizes'] == 0) {goto sizem;} Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274599 Share on other sites More sharing options...
trq Posted October 1, 2011 Share Posted October 1, 2011 Why does what require what? Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274602 Share on other sites More sharing options...
KevinM1 Posted October 1, 2011 Share Posted October 1, 2011 When echoing array values in a double quoted string, you have two options: 1. String concatenation echo "Some string " . $array['key']; 2. Using inline curly braces to force interpolation echo "Some string {$array['key']}"; Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274603 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 1, 2011 Author Share Posted October 1, 2011 $row['sizes'] <<< ' ' are required in this case. Why? Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274604 Share on other sites More sharing options...
trq Posted October 1, 2011 Share Posted October 1, 2011 Because strings are surrounded by quotes in PHP. Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274606 Share on other sites More sharing options...
trq Posted October 1, 2011 Share Posted October 1, 2011 Actually, I completely misread your first post sorry. I didn't see you had the entire thing within double quotes. Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274607 Share on other sites More sharing options...
jcbones Posted October 1, 2011 Share Posted October 1, 2011 When echoing array values in a double quoted string, you have two options: 1. String concatenation echo "Some string " . $array['key']; 2. Using inline curly braces to force interpolation echo "Some string {$array['key']}"; There is actually 3. echo "some string $array[key]". //without quotes around the key Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274685 Share on other sites More sharing options...
KevinM1 Posted October 1, 2011 Share Posted October 1, 2011 Ah, didn't know that. I like the first two options better than the third, as they reinforce consistency by keeping single quotes around the key. Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274693 Share on other sites More sharing options...
PFMaBiSmAd Posted October 1, 2011 Share Posted October 1, 2011 Choice #3 would tend to confuse a noob into thinking that he should not put quotes around associative array names at all, thereby causing problems with undefined constant errors, and introducing inconstant use of php variable syntax. Quote Link to comment https://forums.phpfreaks.com/topic/248217-bull-shit-unexpected-t_encapsed_and_whitespace/#findComment-1274697 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.