我的语法有什么问题吗? (PHP/HTML)
好吧,我已经重复了至少 30 遍,尝试了我能想到的尽可能多的可能组合,你能发现语法错误吗? (显然我不能)。它不显示应有的内容,而是显示页面的实际 html!
代码:
$ct->data[$key][1] =
'<input id="quantity" name='."items[<?=$product_id;?>]".
'type="text" value="'.$ct->data[$key][1].'"
style="background:#FFFFFF url(qty.png) no-repeat 4px 4px;
有人可以告诉我我做错了什么吗?任何帮助/建议都值得赞赏。
谢谢!
Well, I've gone over this atleast 30 times, tried as many possible combinations that I could think of, can you spot the syntax error? (I can't, obviously). It doesn't display what it should be, instead it displays the actual html of the page!
The Code:
$ct->data[$key][1] =
'<input id="quantity" name='."items[<?=$product_id;?>]".
'type="text" value="'.$ct->data[$key][1].'"
style="background:#FFFFFF url(qty.png) no-repeat 4px 4px;
Can someone please tell me what I've done wrong? Any help/advice at all is appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是什么?
我想你的意思是
What is this?
I think you meant
使用短标签是一种非常糟糕的做法。它使代码更难阅读,并且在大多数环境中默认情况下不启用它。这可能会导致像这样的错误。
始终使用完整的
(而不是
)和
而不是
。这将防止许多错误。
然后,看起来您正在尝试在字符串中评估 PHP。
echo "echo 'test'";
永远不会打印 test,它总是打印 echo 'test'。items[]
也是如此。首先,它甚至不是有效的 PHP 语法,其次,即使它确实有效,您也可以使用 $product_id 而不进行任何其他修改:items[$product_id]
。 (编辑:实际上,我什至不确定你想在这里做什么)。我不会详细介绍您的所有代码,但您似乎缺乏该语言的基础知识。回顾一下它们可能会很好!
Using short tags is a very bad practice. It makes code harder to read and it isn't enabled by default on most environments. Which can lead to mistakes like this one.
Always use the full
<?php
(and not<?
) and<?php echo "string"
instead of<?="string">
. This will prevent many mistakes.Then, it looks like you're trying to evaluate PHP in strings.
echo "echo 'test'";
will never print test, it will always print echo 'test'. It's the same thing foritems[<?=$product_id;?>]
. First of all, it isn't even a valid PHP syntax and second of all, even if it was really, you can use $product_id without any other modification :items[$product_id]
. (edit: actually, I'm not even sure what you're trying to do here).I'm not going to go over all your code, but it seems like you lack the basics of the language. It may be good to review them!