Forum Moderators: coopster

Message Too Old, No Replies

What does the "." (dot) mean?

         

neophyte

1:52 am on Sep 19, 2004 (gmt 0)

10+ Year Member



I've seen this a number of times when people of posted code to try to explain a concept or code snippet, but I don't know what it means or it's proper use:

print('well, hello ' . $person . ', nice to meet you!');

I'm talking about the "dot" before and after the $person variable. What is the function of this dot? And is there a tutorial or newbie-type documentation somewhere where it is explained?

Neophyte

caspita

1:57 am on Sep 19, 2004 (gmt 0)

10+ Year Member



it is used just to concatenate strings.

$var = "World!";
echo "hello" . $var;

will output hello World! in the browser.

Another way you will find is:

$str = "Hello ";
$str .= "Wordl!";
echo $str;

output will be the same, in this case .= means 'append to' .. same that if you do $str = $str . "World";

neophyte

2:31 am on Sep 19, 2004 (gmt 0)

10+ Year Member



Ah, okay. I get it. Thanks for the reply Caspita.

mincklerstraat

7:47 am on Sep 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Another thing that's real handy and concatenator-like the combined operator ".=".

You can use it to build up strings.

$a = 'Cigarettes and';
$a .= ' pantyhose';

echo $a;

outputs 'Cigarettes and pantyhose'.

tomda

8:11 am on Sep 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Indeed, this is very handy for sql queries. You can write different queries depending of the value of your variables.

$main_request = "select id from $table where (tags like '%$tab[0]%'";
if ($var!="0") {$main_request .= " OR tagsvar like '%$tab[0]%' ";}
$res_main_request=mysql_query($main_request) or die ("Fail to do the search");