PHP 变量串联

发布于 2024-09-18 22:23:41 字数 608 浏览 10 评论 0原文

我正在尝试将硬编码变量值更改为动态,但似乎无法正确连接...

硬编码值是...

$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 技术交流群。

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

发布评论

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

评论(5

魔法少女 2024-09-25 22:23:41
$token = get_bloginfo('template_directory') . "styles/test/sidebar";

. 是连接运算符,因此您不希望 get_bloginfo() 函数位于引号内。这假设函数返回一个以 / 结尾的字符串

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

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 /

紫罗兰の梦幻 2024-09-25 22:23:41
$token = get_bloginfo('template_directory')."styles/test/sidebar";

你是这个意思吗?您将函数作为字符串而不是函数。

$token = get_bloginfo('template_directory')."styles/test/sidebar";

Is that what you mean? You had the function as a string instead of a function.

听你说爱我 2024-09-25 22:23:41

从您的代码中:

$token = ".get_bloginfo('template_directory')."styles/test/sidebar";

该行开头有一个杂散引号和句点。您可能想要这样做:

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

函数调用不能在字符串内,并且连接运算符 (.) 必须在字符串外部。

From your code:

$token = ".get_bloginfo('template_directory')."styles/test/sidebar";

This line has a a stray quote and period at the beginning. You probably wanted to do:

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

Function calls cannot be within strings, and the concatenation operator (.) must be outside of the string.

临风闻羌笛 2024-09-25 22:23:41

只有字符串应该用引号引起来。

$token = get_bloginfo('template_directory') . "styles/test/sidebar";

Only strings should be wrapped within quotes.

$token = get_bloginfo('template_directory') . "styles/test/sidebar";
第几種人 2024-09-25 22:23:41

你的连接有点不对劲。

尝试:
$token = get_bloginfo('template_directory') 。 '样式/测试/侧边栏';

Your concatination is a bit off.

Try:
$token = get_bloginfo('template_directory') . 'styles/test/sidebar';

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文