Page 1 of 1

$ symbol in print function?

Posted: Sat Nov 20, 2004 11:22 pm
by C_Calav
hi guys, i have this print function that i need to have included in my site, all works fine, but when i go to add the $ (dollar sysmbol) in in front of the shipping for example,

Code: Select all

<td colspan="2" valign="top">$&#123;$shipping&#125;</td>
the shipping amount and the $ dollar sign do not show up.

if however i do not have the $ dollar sign in front of the shipping it does show up.

for example how i have it at the moment.

Code: Select all

print <<<HTMLEOF

   <tr> 
        <td height="30" colspan="3" valign="middle"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td colspan="2" valign="top"><strong>Freight:</strong>&nbsp;</td>
   		 <td colspan="2" valign="top">&#123;$shipping&#125;</td>
      </tr>
      <tr> 
        <td height="30" colspan="3" valign="top"><!--DWLayoutEmptyCell-->&nbsp;</td>
        <td colspan="2" valign="top" align="left"><strong>Total: </strong></td>
		<td colspan="2" valign="top">&#123;$totalCost&#125;</td>
      </tr>	

HTMLEOF;
is this $ dollar sign not allowed to be in the print function can someone please help or explain? thanx!

Posted: Sat Nov 20, 2004 11:49 pm
by rehfeld
looks like it is being evaluated as a variable variable

http://php.net/manual/en/language.varia ... riable.php

Code: Select all

$first = 'second';
$second = 'third';

echo $first; // outputs second
echo ${$first}; // outputs third

// this is because php first evaluates whats in the curly braces, 
// which is the string 'second'

// since there is a variable named $second, it now echos the contents of second


// to avoid this, you must escape the $ symbol like \ $

echo "\$$money";

the board isnt letting me post a \ directly before a $ symbol, so i couldnt show you


or you could just do like this

echo '$' . $money . 'rest of string';

Posted: Sun Nov 21, 2004 12:18 am
by C_Calav
thanx rehfeld, i had a read and looks abit over my head.

i tried the echo thing but got muddled up with the

print <<<HTMLEOF echo '$' HTMLEOF;

is that what you mean?

Posted: Sun Nov 21, 2004 12:30 am
by potsed
try escaping the dollar sign as rehfeld is suggesting like this...

Code: Select all

<td colspan="2" valign="top">\$&#123;$shipping&#125;</td>

Posted: Sun Nov 21, 2004 12:36 am
by C_Calav
that was it! thanx very much,

i have one more problem

now how can i print this:

Code: Select all

<?php
echo number_format($totalCost, 2, ".", ","); 
?>
as this:
\${$shipping} (but with the formatting)

do you get what i mean?

because im in a print function it will not let me, or i do not know how to include the formatting.

does anyone know about this or anything to do with this?

thanx

Posted: Sun Nov 21, 2004 12:52 am
by potsed
Format it in a var

Code: Select all

$shipping = number_format($totalCost, 2, ".", ",");
Then put the formatted var into the print

Posted: Sun Nov 21, 2004 12:54 am
by C_Calav
thanx man, i did something i had the right idea but i didnt dfo it right!

cheers for every ones help