如何在函数调用中使用文本回显 php 变量?

发布于 2024-12-04 18:39:31 字数 465 浏览 1 评论 0原文

使用thumbsup 脚本生成各种事物的评级。这是当前代码:

echo ThumbsUp::item($reviewid)->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

我尝试在 $reviewid 之前添加文本 review_。无论我如何尝试,Dreamweaver 都将停止显示错误,但变量不会传递。我尝试的最后一件事是:

echo ThumbsUp::item('review_$reviewid')->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

Using the thumbsup script to generate ratings for various things. Here is the current code:

echo ThumbsUp::item($reviewid)->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

I'm trying to add the text review_ before $reviewid. No matter what I try, Dreamweaver will stop showing errors, but the variable doesn't pass through. Last thing I tried is:

echo ThumbsUp::item('review_$reviewid')->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

━╋う一瞬間旳綻放 2024-12-11 18:39:31

您尝试过使用双引号吗?除非使用双引号,否则变量(这也是 Perl 的规则)不会插入到字符串中。

//                  v- double quotes-v
echo ThumbsUp::item("review_$reviewid")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

或者,您可以使用字符串连接来执行相同的操作:

echo ThumbsUp::item('review_' . $reviewid)-> ...

Have you tried using double quotes? Variables (and this is the rule for Perl too) won't interpolate into strings unless you use double quotes.

//                  v- double quotes-v
echo ThumbsUp::item("review_$reviewid")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful')

Alternatively, you could use string concatenation to do the same thing:

echo ThumbsUp::item('review_' . $reviewid)-> ...
妥活 2024-12-11 18:39:31

我建议您使用大括号转义变量,因为这种方法允许您使用对象变量,例如:

echo ThumbsUp::item("review_{$reviewid}")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful');

I would recommend you escape variables with curly brackets, as this approach allows you to use object variables, example:

echo ThumbsUp::item("review_{$reviewid}")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful');
但可醉心 2024-12-11 18:39:31

变量不会在“”内扩展,而仅在“”内部扩展。

echo ThumbsUp::item("review_$reviewid")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful');

Variables are not expanded within '', only within "".

echo ThumbsUp::item("review_$reviewid")->template('mini_thumbs2')->format('{UP} out of {TOTAL} people found this review helpful');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文