Jump to content

Switch from single to double quoted and reversed the entity, and now it doesn't


Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.