Php – String Variable Type

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-string-variable-type/
PINTEREST
PINTEREST
INSTAGRAM

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations

Php have variable type string to store text,char or string values. String type generally used to store values like name, surname, explanations, address, questions. String variables do not have any size or length limit theoretically. The only limit is the system memory limit. String can be defined in two ways like below.

  • Single Quote
  • Double Quote

Single Quote

Single quote string definition is very the same of double quote string definition. In this example we will define string variable named $city in a single quote.

Double Quote

Double quote is similar to the single quote but there is one crucial difference. Other variables or expressions can be using in double quote string. Now first look howto use double quote to define a string.

Now as we stated previously use variable named $city in new double quote string definition. New string variable will be $sentence and will include $city variable value inside it.

This will output following line.

LEARN MORE  Linux Bash Arrays and Elements

Multi Line String

String generally defined as single line an short length. But in some situations we may need to define multi line strings. This is very easy where we will just use multi line in single or double quote like below. Both single and double quote can be used to define multi line string.

Escape Sequences

While interacting with string we may need some control or escape secuence characters. These characters are used to insert some special functions. Here the list of escape sequence characters.

  • \n is used for new line
  • \r is used for carriage return
  • \t is used for tab
  • \$ is used for dollar sign
  • \" is used for double quote in string
  • \\ is used for backslash in string

Here is some example about them.

And this code will output like below.

String Concatenation

The last topic about string is string concatenation. Actually we will look string related operations in detail next chapter but concatenation is important and useful operation. Concatenation can be done with point . operator like below.

LEARN MORE  Comparing Strings In Python

In this example we concatenate two string variables named $name and $surname by delimiting them with a single space which concatenated between them.

The output will be like below.

PHP Tutorial Topics

  1. Introduction To PHP
  2. Installing PHP To Linux
  3. Installing PHP To Windows
  4. PHP Hello World Project with Eclipse
  5. PHP Syntax
  6. PHP Variables and Types
  7. PHP String Types
  8. PHP Numeric Type (Integer, Float, Double)
  9. PHP Boolean Type
  10. PHP Arrays
  11. PHP Operators
  12. PHP Ternary Operators
  13. PHP Constants
  14. PHP If..Elseif..Else Conditional Statements
  15. PHP Switch..Case Conditional Statements
  16. PHP For and Foreach Loop Statements
  17. PHP While and Do While Statements
  18. PHP Functions
  19. PHP Class and Objects
  20. PHP Date and Time Operations
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/php-string-variable-type/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)