Php Variable and String

PHP Variable@ Shwetank


A variable is used to store information.
Variables are used for storing values, like text strings, numbers or arrays.

All variables in PHP start with a $ sign symbol.

The correct way of declaring a variable in PHP:
$var_name = value;

New PHP programmers often forget the $ sign at the beginning of the variable. In that case it will not work.

$-  sign must be start
Hello-  is a variable name
5–  is a variable value

Let’s try creating a variable containing a string, and a variable containing a number:
$txt=”Shwetank Education!”;

Example with Output
echo “hello”;

PHP String@ Shwetank


A string variable is used to store and manipulate text.

String variables are used for values that contain characters.
A string can be used directly in a function or it can be stored in a variable.

the PHP script assigns the text “shwetank Education” to a string variable called $txt:
$txt=”shwetank Education”;
echo $txt;

The output of the code above will be:
shwetank Education

The Concatenation Operator

The concatenation operator (.) is used to put two string values together.

To concatenate two string variables together, use the concatenation operator:
$txt1=”shwetank education”;
$txt2=”welcome to you!”;
echo $txt1 . ” ” . $txt2;

The output of the code above will be:
shwetank education welcome to you!

The strlen() function

The strlen() function is used to return the length of a string.

Let’s find the length of a string:

echo strlen(“Shwetank Eucation!”);

The output of the code above will be: