开发者

PHP variable concatenation

开发者 https://www.devze.com 2023-01-16 10:59 出处:网络
I\'m trying to change a hardcoded variable value to dynamic, but can\'t seem to get the concatenation correct...

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 = imagecolorallocat开发者_开发百科e($img, $info["red"], $info["green"], $info["blue"]);
    for ($i = $startPixel-1; $i < $endPixel; $i++)
    {
        imagesetpixel($img, $i, 0, $color);
    }

    imagegif($img, $token.'.gif');
}


$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 /


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

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


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.


Only strings should be wrapped within quotes.

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


Your concatination is a bit off.

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

0

精彩评论

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