为什么PHP不替换字符串中的变量? [英] Why is PHP not replacing the variable in string?

查看:80
本文介绍了为什么PHP不替换字符串中的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么这行简单的代码行不通:

I dont get why this simple line of code does not work:

<?php
$someVariable = 0;
echo 'SomeVariable is $someVariable';
?>

它正在打印出"SomeVariable is $ someVariable",而不是数字0.是否缺少某些内容或必须启用某些配置选项?

It is printing out "SomeVariable is $someVariable" as opposed to the number 0. Is there something I am missing or some configuration option I have to enable?

推荐答案

这是因为您需要使用双引号代替. 当用单引号引起来时,php不会将变量转换为它们的值

That is because you need to use double quote instead. php will not convert variables to their values when surrounded by single quotes

<?php
$someVariable = 0;
echo "SomeVariable is $someVariable";
?>

这篇关于为什么PHP不替换字符串中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆