PHP HOME
PHP Introduction
PHP SETUP
PHP Syntax
PHP Data Types
PHP Outputs
PHP Variable
PHP Constant
PHP Strings
PHP Operators
PHP if else if
PHP Switch
PHP while loop
PHP for loop
PHP Arrays
PHP Functions
PHP Sorting Array
PHP Form Handling
PHP Form Validation
PHP Form Required
PHP Form URL/EMAIL
PHP Form Submit
PHP Contact Form
PHP DATE & TIME
PHP INCLUDE
PHP FILE HANDLING
PHP FILE OPEN/READ
PHP FILE CREATE/WRITE
PHP FILE UPLOAD
PHP SESSION
PHP COOKIES
PHP FILTER
PHP ERROR HANDLING
PHP EXCEPTION
PHP Redirects
PHP with MySQL
PHP WITH MYSQL DB
MYSQL CONNECT
MYSQL CREATE DATABASE
SELECT DATABASE
MYSQL CREATE TABLE
MYSQL INSERT DATA
MYSQL SELECT DATA
MYSQL UPDATE DATA
MYSQL DELETE DATA
MYSQL ORDER
MYSQL LIMIT
MYSQL LAST ID
PHP string is a collection of characters i.e. "Hello John!". A PHP string value must stay with " ".
What is PHP string?
When a value stays within " " then it's called be PHP String. Like "Hello John!"
These are valid example of strings in PHP
<!DOCTYPE html>
<html>
<body>
<?php
$first_string = 'This is a string in single quotes';
$second_string = "This is a string in double quotes";
?>
<p>First String : <?php echo $first_string;?></p></br>
<p>Second String : <?php echo $second_string;?></p></br>
</body>
</html>
The above code produces the following results
Outputs: First String: This is a string in single quotes
Second String: This is a string in double quotes
String Concatenation Example
<!DOCTYPE html>
<html>
<body>
<?php
$first_string = 'This is a string';
$second_string = "This is another string";
?>
<p>Concatenation in PHP : <?php echo $first_string . 'And' .$second_string;?></p>
</body>
</html>
The above code produces the following results
Outputs: Concatenation in PHP: This is a string And This is another string
Some PHP Strings Function Example
<!DOCTYPE html>
<html>
<body>
<?php
$string = 'This is a string';
?>
<p>Word Count : <?php echo str_word_count($string);?></p></br>
<p>String length : <?php echo strlen($string);?></p></br>
<p>String position : <?php echo strpos($string, 'string');?></p></br>
<p>Reverse String : <?php echo strrev($string);?></p></br>
</body>
</html>
The above code produces the following results
Outputs: Word Count: 4
String length: 16
String position: 10
Reverse String: gnirts a si sihT