Freedom-n-Democrazy Posted October 6, 2011 Share Posted October 6, 2011 I have: {$content['size']} inside echo ""; I had to switch the quotes around because I added something else that required me to do so, so it now sits at this: {$content["size"]} inside echo ''; Before I made the quote switch, it was echoing "Large", which is correct. Now after the switch, it echo's "{$content["id"]} ". Why?! I've tried 567568758654 different combinations of quotes and removing {} and stuff but non of them fix it. I don't even see why its suddenly not even echoing! All I did was quote reverse! Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/ Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Ok, the original post was written shit house. I will start again I had: echo "{$content['size']}"; ... and this echoed "Large", which is correct. I then switched the quotes around, so its now like this: echo '{$content["size"]}'; The problem now is that instead of echoing "Large", it echo's "{$content["id"]} ". Why?! Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276371 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 You cannot simply "reverse the quotes" PHP has a wonderful thing called interpolation. Interpolation can only happen inside a double quoted string, for single quoted strings you will have to concatenate. That answers the why $cool = 'Something'; echo 'This is $cool'; // Output: This is $cool echo "This is $cool"; // Output: This is Something So the short answer would be, dont put variables into single quoted strings. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276372 Share on other sites More sharing options...
MasterACE14 Posted October 6, 2011 Share Posted October 6, 2011 for single quoted strings you will have to concatenate. continuing from Buddski's example... $cool = 'Something'; echo 'This is' . $cool; // Output: This is Something (concatenated) Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276374 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Sweet, I think I know how to get out of this one then.... I'll try it. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276375 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 I suck so hard its unbelievable! I tried braking out with: .size. ".size." "'.size.'" "size" 'size' '.size.' "'size'" '"size'" Fail. I then tried $content['size'] = $size; echo $size; ... and tried every combination again as listed above. Total failure! Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276379 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 Did you try echo $size; Perhaps posting the entire string (with the part that "required" you to change the code) we can get a better understanding. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276380 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Yeah, I tried it as just $echo also. Heres the code: echo ' <IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png"> <BR> <B>Size:</B> {$content["size"]} <BR> <BR> '; Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276381 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 The whole echo statement would be good, not just the end of it.. Edit: Better Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276382 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 This is it: echo ' <IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png"> <B>Product ID:</B> {$content["id"]} <BR> <B>Size:</B> {$content["size"]} <BR> <B>Price: $</B> $row[price] AUD <BR> <BR> '; Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276385 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 As previously said, you CANNOT parse variables in a single quoted string unless you concatenate it. echo ' <IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png"> <BR> <B>Size:</B> '.$content["size"].' <BR> <B>Price: $</B> '.$row['price'].' AUD <BR> <BR>'; Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276386 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Yeah, you said: $cool = 'Something'; echo 'This is $cool'; // Output: This is $cool echo "This is $cool"; // Output: This is Something I then tried to copy the logic and failed. I then tried $content['size'] = $size; echo $size; ... and tried every combination again as listed above. Total failure! Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276388 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 From looking at the supplied code (the last revision) you didnt copy the logic at all. If your script is not echoing anything at all, perhaps you have an error somewhere else in your script that is halting the execution. Do you still have error_reporting enabled? Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276390 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Like I said in my original post, everything working fine, except the size not longer echo's "Large" since swapping the quotes, it now echo's "{$content["id"]}". http://i55.tinypic.com/34f01f6.png Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276394 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 Miss this one? It shows you exactly what you missed. To further clarify, wrapping {} around a variable does nothing in a single quoted string either, this is (basically) for doing more complex things in double quoted or HEREDOC strings. As previously said, you CANNOT parse variables in a single quoted string unless you concatenate it. echo ' <IMG alt="" src="../products/'.$row['fordir'].'/'.$row['categorydir'].'/'.$row['id'].'/thumbnail.png"> <BR> <B>Size:</B> '.$content["size"].' <BR> <B>Price: $</B> '.$row['price'].' AUD <BR> <BR>'; Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276398 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Ah shit you just beat me to it I was four attempts away from trying that combination of '..'. I looked at it from another perspective. I said to myself stop focussing on the fact I reversed the strings, and yeah, things started making sense. lol Thanks but! Hey, I noticed you did this yeah..: <B>Size:</B> '.$content["size"].' <BR> <B>Price: $</B> '.$row['price'].' Size has the double while price has the single. I have both mine single. Is there any difference? EDIT: In fact, it works with no quotes.. but I am going to keep the single quotes in to keep consistency amongst my code. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276402 Share on other sites More sharing options...
Buddski Posted October 6, 2011 Share Posted October 6, 2011 No difference at all.. that entered key is just a string at the end of the day. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276404 Share on other sites More sharing options...
trq Posted October 6, 2011 Share Posted October 6, 2011 You really need to take a look at strings. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276406 Share on other sites More sharing options...
trq Posted October 6, 2011 Share Posted October 6, 2011 Sorry, try: http://php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276407 Share on other sites More sharing options...
Freedom-n-Democrazy Posted October 6, 2011 Author Share Posted October 6, 2011 Yes, your right man! I will read that entire page in 10 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/248537-switch-from-single-to-double-quoted-and-reversed-the-entity-and-now-it-doesnt/#findComment-1276415 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.