N Seminar of Naveen&
N Seminar of Naveen&
Example
<?php
echo strlen("Hello world!"); // outputs 12
?>
Try it Yourself »
Example
<?php
echo str_word_count("Hello world!"); // outputs 2
?>
strrev() - Reverse a String
The PHP strrev() function reverses a string.
Example
<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>
Example
<?php
echo strpos("Hello world!", "world"); // outputs 6
?>
Example
<?php
echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello
Dolly!
?>
PHP Constants
A constant is an identifier (name) for a simple value. The value cannot be changed
during the script.
A valid constant name starts with a letter or underscore (no $ sign before the constant
name).
Note: Unlike variables, constants are automatically global across the entire script.
Seminar 2
Syntax
Parameters:
•name: Specifies the name of the constant
•value: Specifies the value of the constant
•case-insensitive: Specifies whether the constant name should be case-
insensitive. Default is false
Example
In PHP7, you can create an Array constant using the define() function.
Example
<?php
define("cars", [
"Alfa Romeo",
"BMW",
"Toyota"
]);
echo cars[0];
?>
Constants are automatically global and can be used across the entire script.
Example
This example uses a constant inside a function, even if it is defined outside the
function:
<?php
define("GREETING", "Welcome to W3Schools.com!");
function myTest() {
echo GREETING;
}
myTest();
?>