Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts

    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?!

  • #2
    Regular Coder
    Join Date
    Oct 2011
    Posts
    237
    Thanks
    11
    Thanked 5 Times in 5 Posts
    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

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    If you only have a variable you won't need quotes at all.
    Try it like this:
    PHP Code:
    echo $content['size']; 

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    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"]; 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    There is a tip in my signature about quotes. Take a look as it will explain this to you in greater detail.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    274
    Thanks
    38
    Thanked 0 Times in 0 Posts
    This fixed it:

    PHP Code:
    '.$content['size'].' 

  • #7
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    You could also do it without quotes

  • #8
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by Wanna View Post
    You could also do it without quotes
    Only inside double quotes.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #9
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Quote Originally Posted by tangoforce View Post
    Only inside double quotes.
    I mean like this
    PHP Code:
    echo $content['size']; 

  • #10
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,325
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Ah, I thought you meant

    PHP Code:
    '.$content[size].' 
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •