PHP String

PHP Strings

They are sequences of characters, like "PHP supports string operations".

Following are valid examples of string

Singly quoted strings are treated almost literally, whereas doubly quoted strings replace variables with their values as well as specially interpreting certain character sequences.

This will produce following result:

There are no artificial limits on string length - within the bounds of available memory, you ought to be able to make arbitrarily long strings.

Strings that are delimited by double quotes (as in "this") are preprocessed in both the following two ways by PHP:

  • Certain character sequences beginning with backslash (\) are replaced with special characters
  • Variable names (starting with $) are replaced with string representations of their values.

String Concatenation Operator

To concatenate two string variables together, use the dot (.) operator:

Valid and invalid constant names:

This will produce following result:

If we look at the code above you see that we used the concatenation operator two times. This is because we had to insert a third string.

Between the two string variables we added a string with a single character, an empty space, to separate the two variables.



© 2015-16 All Rights Reserved Tech9schools