当前位置: 动力学知识库 > 问答 > 编程问答 >

PHP string concatenation

问题描述:

The code below didn't concat the strings for me, how come ?

$test = $this->address . $this->url;

echo $test; // prints the content of $this->address only

But this code works:

$begin = $this->address;

$end = $this->url;

$test = $begin.$end;

echo $test; // prints the concatenation

What am I missing?

网友答案:

This is totally valid code.

Do a

echo 'value of url: '.$this->url;

when you a line before you try to concatenate the two strings. It must be definetly empty. If it's not empty try a concatenation like this:

$test = '' . $this->address . $this->url;
网友答案:

Check echo $this->url
it might be the case that the variable is empty

分享给朋友:
您可能感兴趣的文章:
随机阅读: