PHP 变量串联
我正在尝试将硬编码变量值更改为动态,但似乎无法正确连接...
硬编码值是...
$token = "../wp-content/themes/mytheme/styles/test/sidebar";
并且我正在尝试将其替换为...
$token = ".get_bloginfo('template_directory')."styles/test/sidebar";
但它不起作用与我对值进行硬编码时相同。
我缺少什么?
这是代码的其余部分(imagegif 函数永远不会使用动态生成的变量触发......
$color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
for ($i = $startPixel-1; $i < $endPixel; $i++)
{
imagesetpixel($img, $i, 0, $color);
}
imagegif($img, $token.'.gif');
}
I'm trying to change a hardcoded variable value to dynamic, but can't seem to get the concatenation correct...
The hardcoded value is...
$token = "../wp-content/themes/mytheme/styles/test/sidebar";
And I'm trying to replace that with...
$token = ".get_bloginfo('template_directory')."styles/test/sidebar";
But its not working the same as when I hardcode the value.
What am I missing?
Here's the rest of the code (the imagegif function never fires with the dynamically generated variable...
$color = imagecolorallocate($img, $info["red"], $info["green"], $info["blue"]);
for ($i = $startPixel-1; $i < $endPixel; $i++)
{
imagesetpixel($img, $i, 0, $color);
}
imagegif($img, $token.'.gif');
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
.
是连接运算符,因此您不希望 get_bloginfo() 函数位于引号内。这假设函数返回一个以/
结尾的字符串The
.
is the concatenation operator, so you wouldn't want the get_bloginfo() function inside of quotes. This assumes the function returns a string that ends in a/
你是这个意思吗?您将函数作为字符串而不是函数。
Is that what you mean? You had the function as a string instead of a function.
从您的代码中:
该行开头有一个杂散引号和句点。您可能想要这样做:
函数调用不能在字符串内,并且连接运算符 (
.
) 必须在字符串外部。From your code:
This line has a a stray quote and period at the beginning. You probably wanted to do:
Function calls cannot be within strings, and the concatenation operator (
.
) must be outside of the string.只有字符串应该用引号引起来。
Only strings should be wrapped within quotes.
你的连接有点不对劲。
尝试:
$token = get_bloginfo('template_directory') 。 '样式/测试/侧边栏';
Your concatination is a bit off.
Try:
$token = get_bloginfo('template_directory') . 'styles/test/sidebar';