PHP special Characters

I have created a variable from a query;
$limit = "$".$extra['item_options']['accessories_value'] + $extra['item_options']['bike_value'].'<br />';

No matter what I try, I can't seem to get the Dollar sign ($) to print out when the variable is echoed.
LVL 7
rgranlundAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Then that line isn't the problem.  I have lots of code like that that prints '$' just fine.  Something else is removing it.  Do the other items print as they should?  You might try putting the addition part in parenthesis or better yet, do it before that line and assign it to a simple variable.  Doing operations in the middle of string doesn't always work.
$valuesum = $extra['item_options']['accessories_value'] + $extra['item_options']['bike_value'];
$limit = "$".$valuesum.'<br />';

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
Try wrapping the dollar sign in single quotes.
http://iconoun.com/demo/temp_rgranlund.php
<?php // demo/temp_rgranlund.php

/**
 * http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28655783.html
 */
error_reporting(E_ALL);

echo 'Here is the Dollar Sign you wanted: $';

Open in new window

0
Yohan CourbeIT ManagerCommented:
PHP interpolates variables only with double quote,  as Ray says, use simple quotes. I even suggest you to use sprintf for a proper formatting:

<?php
$amount=100.0;
echo '$'.$amount; // output: $ 100
echo sprintf("$ %.02f", $amount); // output: $ 100.00
?>

Cheers
0
rgranlundAuthor Commented:
I tried all of the solutions and the one Dave suggested worked for me.  I think it has something to do with my CMS stipping certain characters at certain times.  I'm not sure.  I got it fixed and that is what matters.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.