0% found this document useful (0 votes)
28 views5 pages

N Seminar of Naveen&

The document discusses PHP string and constant functions: 1) It explains functions like strlen(), str_word_count(), strrev(), strpos(), and str_replace() that manipulate and analyze strings. 2) It then covers defining constants in PHP using the define() function and shows examples of defining constant values and arrays. 3) The last section notes that constants are global and can be used across an entire PHP script, including inside functions.

Uploaded by

Mohd Umar Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

N Seminar of Naveen&

The document discusses PHP string and constant functions: 1) It explains functions like strlen(), str_word_count(), strrev(), strpos(), and str_replace() that manipulate and analyze strings. 2) It then covers defining constants in PHP using the define() function and shows examples of defining constant values and arrays. 3) The last section notes that constants are global and can be used across an entire PHP script, including inside functions.

Uploaded by

Mohd Umar Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Seminar 1

strlen() - Return the Length of a String


The PHP strlen() function returns the length of a string.

Example

Return the length of the string "Hello world!":

<?php
echo strlen("Hello world!"); // outputs 12
?>

Try it Yourself »

str_word_count() - Count the Number of Words in


a String
The PHP str_word_count() function counts the number of words in a string.

Example

Count the number of word in the string "Hello world!":

<?php
echo str_word_count("Hello world!"); // outputs 2
?>
strrev() - Reverse a String
The PHP strrev() function reverses a string.

Example

Reverse the string "Hello world!":

<?php
echo strrev("Hello world!"); // outputs !dlrow olleH
?>

strpos() - Search For a Text Within a String


The PHP strpos() function searches for a specific text within a string. If a match is
found, the function returns the character position of the first match. If no match is
found, it will return FALSE.

Example

Search for the text "world" in the string "Hello world!":

<?php
echo strpos("Hello world!", "world"); // outputs 6
?>

str_replace() - Replace Text Within a String


The PHP str_replace() function replaces some characters with some other characters
in a string.

Example

Replace the text "world" with "Dolly":

<?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

Create a PHP Constant


To create a constant, use the define() function.

Syntax

define(name, value, case-insensitive)

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

Create a constant with a case-sensitive name:


<?php
define("GREETING", "Welcome to W3Schools.com!");
echo GREETING;
?>

PHP Constant Arrays

In PHP7, you can create an Array constant using the define() function.

Example

Create an Array constant:

<?php
define("cars", [
"Alfa Romeo",
"BMW",
"Toyota"
]);
echo cars[0];
?>

Constants are Global

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();
?>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy