Need a Website Or Web Application Or Any Help In Code , Contact Us: +91 9437911966 (Whatsapp), Note: Paid Service
Students Tutorial app relased. Download Now.

PHP String with example

A string is can have letters, numbers, special characters and arithmetic values or combination of all.

Example: Hello World !

Example: Hello World ! 123

Above both example are string.

To assign a string to a variable is there is two way.

Example

$string=‘Hello World !’;
$string_two=“Hello World !”;

Run It Yourself »

You can use both single quotation or double quotation.But there is a small difference between single quotation and double quotation.

single quotation

  1. Single quoted strings are the easiest way to specify string.
  2. It is faster than double quotation.

double quotation

  1. Double quotes force PHP to specify the string.
  2. It is less faster than single quotation.

So now in our mind a big confusion come that where to use single quotation and where to use double quotation.

Best example to under stand.

Example

<?php
$a=‘Hello';
echo '$a World’;
?>

Run It Yourself »

Output: $a World

Example

<?php
$a=‘Hello';
echo "$a World";
?>

Run It Yourself »

Output: Hello World