1

this cause error:

$xml .= "\t<team id=\"$team['id']\"";

this doesn't cause error:

$xml .= "\t<team id=\"\"";

What's the problem?

Salman Arshad
273k85 gold badges450 silver badges540 bronze badges
asked Dec 24, 2012 at 10:48

5 Answers 5

6

You can either remove the single quotes:

$xml .= "\t<team id=\"$team[id]\"";

Or you can use the curly brackets inside double quoted strings using one of the following syntax:

$xml .= "\t<team id=\"{$team['id']}\"";
$xml .= "\t<team id=\"${team['id']}\"";

Reference (scroll down to the "variable parsing" section).

Few more examples:

echo "$team[id]";
echo "{$team['first name']}"; // e.g. when there are spaces in key names
echo "{${getVarName()}}"; // e.g. when we cannot use $ directly
answered Dec 24, 2012 at 10:53
Sign up to request clarification or add additional context in comments.

Comments

2

This should work:

$xml .= "\t<team id=\"$team[id]\"";

See how I removed the single quotes around the id.

answered Dec 24, 2012 at 10:53

Comments

1

Try this:

$xml .= "\t<team id='".$team['id']."'";
answered Dec 24, 2012 at 10:54

Comments

1

Try This

$xml .= "\t<team id=\"".$team['id']."\"";

Or you can use the curly brackets like this

$xml .= "\t<team id=\"{$team['id']}\"";
answered Dec 24, 2012 at 10:52

Comments

0

I think the problem is the $team['id'] more than the double quotes.

Have you tried:

$xml .= "\t<team id=\"".$team['id']."\""; 
answered Dec 24, 2012 at 10:53

2 Comments

by doing this the \t will no longer be interpreted as a tab space
totally true, changing to double quotes again.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.