Jacob Kranz
Jacob Kranz

Reputation: 951

end variable name in string w/ double quotes

Have I missed something in my years of php or is there no way to do this:

$var = "testString";
echo "$varAndRestOfStringConctd";
// testStringAndRestOfStringConctd

Is there any other way of writing that besides:

echo $var.'AndRestOfStringConctd';

Upvotes: 0

Views: 46

Answers (3)

Phil
Phil

Reputation: 164733

RTM ~ http://php.net/manual/language.types.string.php#language.types.string.parsing.complex

echo "{$var}AndRestOfStringConctd";

An alternative is the often forgotten printf / sprintf functionality

printf('%sAndRestOfStringConctd', $var);

Upvotes: 1

Anonymous
Anonymous

Reputation: 12017

You can put the variable in curly brackets/braces:

$var = "testString";
echo "{$var}AndRestOfStringConctd";

That tells PHP where the variable ends.

Upvotes: 0

alex
alex

Reputation: 490143

Use braces.

echo "${var}AndRestOfStringConctd";

Upvotes: 1

Related Questions