dongying2112 2013-09-18 20:45
浏览 41
已采纳

美元符号和数字(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.

  • 写回答

3条回答 默认 最新

  • doujie4787 2013-09-18 20:46
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)