Search code examples
phpjoomlajumi

Dollar sign and digits (Joomla + Jumi)


I have db with this string content:

[$3] [$ 3] [$3.2]

Need to echo it as it is.

When try to echo

echo "[$3] [$ 3] [$3.2]";

got this:

[] [$ 3] [.2]

Tried urlencode, htmlspecialchars, but didn't succeed.

How do I echo and get this?

[$3] [$ 3] [$3.2]

EDIT:

single quotes is not giving wanted result.

echo '[$3] [$ 3] [$3.2]';

[] [$ 3] [.2]

My php version is 5.2.14 and I am using Joomla.

EDIT2:

I figured out, the reason it's not working with single quotes is because of Joomla + Jumi. If I use pure php - it works ok.


Solution

  • Use single quotes if you don't want the variable values to be interpolated.

    From the PHP manual:

    Note: Unlike the double-quoted and heredoc syntaxes, variables and escape sequences for special characters will not be expanded when they occur in single quoted strings.

    echo '[$3] [$ 3] [$3.2]';
    

    The quotes shouldn't matter for this particular case as PHP variables can't start with numbers.

    For example:

    echo '[$3] [$ 3] [$3.2]'; // single-quoted
    

    will have the same effect as:

    echo "[$3] [$ 3] [$3.2]"; // double-quoted
    

    And both should output:

    [$3] [$ 3] [$3.2]
    

    But, for valid variables, the above rules apply.

    Example:

    $var = 'foo';
    $string = 'this is a string with $var';
    echo $string;
    

    Output:

    this is a string with $var
    

    Demo!