开发者

How to echo php variable with text inside a function call?

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')


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)-> ...


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');


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');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜