PHP string is sequences of characters, like "Hello, i am very good in php".
The following are valid examples of string
<?php
$string_1 = "String one";
$string_2 = "String sequences of characters";
?>
Single-quoted strings are treated almost literally, and double-quoted strings change the variable with their values
<?php
$string_1 = "String one";
$string_2 = "String sequences of characters";
//Single-quoted
$literally = 'My $string_1 will not print!\\n';
//Single-quoted will not print
$double_quoted = 'My $string_2 will print!\\n';
//// Concatenation Of two String
$concatenation = "My " . $string_1 . " will print!\\n";
echo $literally . "\n";
echo $double_quoted . "\n";
echo $concatenation . "\n";
?>
output:
My $string_1 will not print!\n
My $string_2 will print!\n My String one will print!\n |
Concatenation Of two String
he first is the concatenation operator ('. '), which returns the concatenation of its right and left arguments. The second is the concatenating assignment operator (' . = '), which appends the argument on the right side to the argument on the left side.
To concatenate two string variables together, use the dot (.) operator −
#test.php
<?php
$string_1 = "String one";
$string_2 = "too";
//Concatenation Of two String
$concatenation = "My " . $string_1 . " will print and Second print ".$string_2;
echo $concatenation;
?>
output:
My String one will print and Second print too |
PHP strlen() function
The strlen() function is used to find the length of a string.
<?php
echo strlen("Hello world!");
?>
output:
12 |
PHP strpos() function
The strpos() function is used to search for a String or character within a string .
<?php
echo strpos("Hello world!","wo");
?>
output:
6 |