-1

When I use this code:

    $message = "Transaction ID: " . echo $transid . "\n\nURL: " . echo $url . "\n\nAnchor Text: " . echo $anchortext . "\n\nEmail: " . echo $email;

I get this error:

Parse error: syntax error, unexpected T_ECHO in [file location] on line 35

Line 35 is that above line of code.

Any ideas?

KriiV
  • 1,882
  • 4
  • 25
  • 43

3 Answers3

3

When you're trying to "build" your string, you don't need the echo statements.

For instance, you concatenate strings like this:

$str = "first part" . "second part";

or

$str = "first part" . $someVariable;

In your case, you would simply do:

$message = "Transaction ID: " . $transid . "\n\nURL: " . $url . "\n\nAnchor Text: " . $anchortext . "\n\nEmail: " . $email;
newfurniturey
  • 37,556
  • 9
  • 94
  • 102
1

Double quoted strings allow to interpolate variables:

$message = "Transaction ID: $transid\n\nURL: $url\n\nAnchor Text: $anchortext\n\nEmail: $email";

That's the one feature that separates scripting languages from static languages. Utilize it.

See also What is the difference between single-quoted and double-quoted strings in PHP? (in particlar "heredoc" strings).

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291
0
$message = "Transaction ID: " . $transid . "\n\nURL: " . $url . "\n\nAnchor Text: " . $anchortext . "\n\nEmail: " . $email;

this should work for you.

Now just use $message variable to echo you message.

EDIT

the problem to getting the error because you are using the echo into your string that was :

$message = "Transaction ID: " . echo $transid . "\n\nURL: " . echo $url . "\n\nAnchor Text: " . echo $anchortext . "\n\nEmail: " . echo $email;
jogesh_pi
  • 9,762
  • 4
  • 37
  • 65