43

What does the following command do in PHP?

. $string   // ($string is something which I declared in the program)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
John Tor
  • 837
  • 2
  • 8
  • 11

5 Answers5

83

On its own, that does nothing at all (it's not valid syntax). However, if you have something like this:

<?php

$string1 = "Hello ";
$string2 = "world!";
$string = $string1 . $string2;

echo $string;

?>

You will see Hello world!. The . is the string concatenation operator.

Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
20

Taken alone, this is a syntax error. The dot . is the concatenation operator that converts its arguments to strings and concatenates them. For example,

<?php
$string = "x";
$s = 42 . $string;
// $s is now "42x"
phihag
  • 278,196
  • 72
  • 453
  • 469
  • w3fools.com says: "Today, W3Schools has largely resolved these issues and addressed the majority of the undersigned developers' concerns." So it is now pretty accurate. – Elijah Mock Dec 08 '19 at 02:55
3

Your statement would throw back an error.

The "dot" is a string concatenator. That is, it helps you to combine strings together into another string.

Example. $full = $part1 . $part2;

Concerning getting started: That's a difficult question. PHP.NET will be your functional looking site. Google-ing just about anything on PHP will direct you there. I'd look at getting a localhost setup of PHP/MySQL/Apache. If you're on a Windows machine, you can get a WAMP server setup.

http://www.wampserver.com/en/

This will drastically speed up your development and testing time. Don't try to FTP everything up to a Web server, as this approach will waste away 10-15% of your working time. Work smart - work local.

Find an existing project (Open Source) with a great community and just try to start something. For example, I recently created DogFriendlyOlrando.com based on WordPress. I was curious as to the abilities of WordPress. It was a fun little project and gave me a good understanding of WordPress' capabilities. You'll learn the most from just diving in and doing. Good luck!

jjwdesign
  • 3,272
  • 8
  • 41
  • 66
0

Two string operators are available. The first is the concatenation operator ('.') that returns its right and left argument concatenation. Second is the concatenation operator of assignment ('.='), which adds the right-hand argument to the left-hand argument. For further details, please read Assignment Operators

Sam
  • 11
  • 1
  • 1
  • 5
-2

The output is displayed directly to the browser like as a given below:

. $string   // ($string is something which I declared in the program)
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131