$message = " "; gives error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
plodos
Forum Newbie
Posts: 11
Joined: Wed Jan 30, 2008 12:16 pm

$message = " "; gives error

Post by plodos »

Code: Select all

 
$message= '
<table width="522" height="235" border="0">
<tbody>
  <tr>
    <td width="105" height="23" bgcolor="#CCCCCC">Name Surname: </td>
    <td width="403" bgcolor="#CCCCCC">{$name} {$surname}</td>
  </tr>
  <tr>
    <td height="23" valign="top">Institution:</td>
    <td>{$institution}</td>
  </tr>
  </tbody>
</table>';
 
That code gives an error, I cant see the variables..output is like that
Name Surname: {$name} {$surname}
Institution:{$institution}
but it must be like that
Name Surname: Plodos MAmas
Institution:Software Group

Could you help me, whats the problem ?



and whats the output of this code

Code: Select all

<td width="403" bgcolor="#CCCCCC">{$name} {$surname}</td>
like Plodos Mamas or PlodosMamas(side by side)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: $message = " "; gives error

Post by Christopher »

Try heredoc style:

Code: Select all

 
$message= <<<TABLE
<table width="522" height="235" border="0">
<tbody>
  <tr>
    <td width="105" height="23" bgcolor="#CCCCCC">Name Surname: </td>
    <td width="403" bgcolor="#CCCCCC">{$name} {$surname}</td>
  </tr>
  <tr>
    <td height="23" valign="top">Institution:</td>
    <td>{$institution}</td>
  </tr>
  </tbody>
</table>
TABLE;
"TABLE" is a name that you make up to define the start/end of the block.
(#10850)
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Re: $message = " "; gives error

Post by Stryks »

Just as a side note to keep in mind, PHP doesn't do variable replacements on strings passed with a single quote.

Code: Select all

$x = 'sleepy'; echo "I am $x.";
... will produce
I am sleepy
.

Code: Select all

$x = 'sleepy'; echo 'I am $x.';
.. will produce
I am $x
.

Attempting variable manipulation on HTML segments is a nightmare with double quotes, leaving you with 1001 escaped double slashes ....

Code: Select all

echo "<p class=\"myclass\">My nickname is \"$nickname\".</p>";
So heredoc to the rescue. :)
Post Reply