PHP 输入带有变量的文本
考虑以下用于从文本文件打印问题的代码:
foreach ($lines as $line_num => $line) {
if($line_num%3 == 1){
echo 'Question '.$count.':'.'<br/>'.'<input type="text" value="$line" class="tcs"/>'.'<br/>';
我已经尝试了许多字符串转义组合。问题是我得到的是 $line
在文本字段内而不是变量值。非常感谢任何帮助。
Consider the following code for printing questions from text file:
foreach ($lines as $line_num => $line) {
if($line_num%3 == 1){
echo 'Question '.$count.':'.'<br/>'.'<input type="text" value="$line" class="tcs"/>'.'<br/>';
I've tried many string escaping combinations. The problem is that I get $line
inside the text field instead of the variable value. Any help is greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从
'
带引号的字符串中删除变量,或使用"
以便解释变量。或者
第一个选项更好,因为您不必转义其他任何内容。
Remove the variable from the
'
quoted string, or use"
so the variable is interpreted.or
The first option is better, since you don't have to escape anything else.
你尝试过吗:
Did you try:
变量不会在单引号字符串中进行处理。您需要使用双引号或其他插入方式(例如串联)。
Variables don't get processed in single quoted strings. You need to use double quotes or another way of inserting them (such as concatenation).