Lokang 

PHP and MySQL

String

In PHP, a string is a sequence of characters, represented by enclosing the characters in single or double quotes:

$string1 = 'This is a string';
$string2 = "This is also a string";

You can use the concatenation operator (.) to combine multiple strings into a single string:

$string1 = 'Hello';
$string2 = 'world';
$string3 = $string1 . ' ' . $string2; // 'Hello world'

You can also use the concatenation assignment operator (.=) to append a string to the end of another string:

$string = 'Hello';
$string .= ' world'; // 'Hello world'

You can access individual characters in a string using array notation, with the index of the character starting at 0 for the first character:

$string = 'Hello';
echo $string[0]; // 'H'
echo $string[4]; // 'o'

You can use the strlen() function to get the length of a string, and the strpos() function to find the position of a substring within a string:

$string = 'Hello world';
echo strlen($string); // 11
echo strpos($string, 'world'); // 6

PHP also provides a number of string manipulation functions, such as substr(), strtolower(), and strtoupper(), that you can use to manipulate strings in various ways.

Example:

<?php
$string = 'Hello world';
echo strtoupper($string) . "\n"; // 'HELLO WORLD'
echo strtolower($string) . "\n"; // 'hello world'
echo substr($string, 6) . "\n"; // 'world'
echo substr($string, 0, 5) . "\n"; // 'Hello'
echo str_replace('world', 'Earth', $string) . "\n"; // 'Hello Earth'
?>