Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2011, 10:03 AM   PM User | #1
FlashDance
Regular Coder

 
Join Date: Sep 2011
Posts: 274
Thanks: 38
Thanked 0 Times in 0 Posts
FlashDance can only hope to improve
Strange echo effect after reversing quotes

I had:
PHP Code:
echo "{$content['size']}"
... and this echoed "Large", which is correct.

I then switched the quotes around, so its now like this:
PHP Code:
echo '{$content["size']}; 
The problem now is that instead of echoing "Large", it echo's "{$content["id"]} ".

Why?!
FlashDance is offline   Reply With Quote
Old 10-06-2011, 10:07 AM   PM User | #2
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
Quote:
Originally Posted by FlashDance View Post
I had:
PHP Code:
echo "{$content['size']}"
... and this echoed "Large", which is correct.

I then switched the quotes around, so its now like this:
PHP Code:
echo '{$content["size']}; 
The problem now is that instead of echoing "Large", it echo's "{$content["id"]} ".

Why?!
you have ["size'] instead of ["size"] but that should throw up a error rather than that
devinmaking is offline   Reply With Quote
Old 10-06-2011, 10:16 AM   PM User | #3
Wanna
Regular Coder

 
Join Date: Sep 2011
Posts: 128
Thanks: 2
Thanked 21 Times in 21 Posts
Wanna is an unknown quantity at this point
If you only have a variable you won't need quotes at all.
Try it like this:
PHP Code:
echo $content['size']; 
Wanna is offline   Reply With Quote
Old 10-06-2011, 10:20 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
PHP doesn't parse the variables enclosed inside singles quotes, but it does for the double quotes. Is there any specific reason to interchange the quotes? Why don't you just use
PHP Code:
echo $content['size']; 
or
PHP Code:
echo $content["size"]; 
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 10-06-2011, 11:08 AM   PM User | #5
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
There is a tip in my signature about quotes. Take a look as it will explain this to you in greater detail.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 10-06-2011, 11:49 AM   PM User | #6
FlashDance
Regular Coder

 
Join Date: Sep 2011
Posts: 274
Thanks: 38
Thanked 0 Times in 0 Posts
FlashDance can only hope to improve
This fixed it:

PHP Code:
'.$content['size'].' 
FlashDance is offline   Reply With Quote
Old 10-06-2011, 01:19 PM   PM User | #7
Wanna
Regular Coder

 
Join Date: Sep 2011
Posts: 128
Thanks: 2
Thanked 21 Times in 21 Posts
Wanna is an unknown quantity at this point
You could also do it without quotes
Wanna is offline   Reply With Quote
Old 10-06-2011, 02:58 PM   PM User | #8
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Wanna View Post
You could also do it without quotes
Only inside double quotes.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 10-06-2011, 03:07 PM   PM User | #9
Wanna
Regular Coder

 
Join Date: Sep 2011
Posts: 128
Thanks: 2
Thanked 21 Times in 21 Posts
Wanna is an unknown quantity at this point
Quote:
Originally Posted by tangoforce View Post
Only inside double quotes.
I mean like this
PHP Code:
echo $content['size']; 
Wanna is offline   Reply With Quote
Old 10-06-2011, 06:08 PM   PM User | #10
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Ah, I thought you meant

PHP Code:
'.$content[size].' 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:02 AM.


Advertisement
Log in to turn off these ads.