Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

Modify Strings

Upper Case

Example

The strtoupper() function converts the string to uppercase.

$x = "Hello World!";
echo strtoupper($x);

Lower Case

Example

The strtolower() function converts the string to lowercase.

$x = "Hello World!";
echo strtolower($x);

Replace String

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

Example

Replace the text “World” with “Dolly”:

$x = "Hello World!";
echo str_replace("World", "Dolly", $x);

Reverse a String

The PHP strrev() function reverses a string.

Example

Reverse the string “Hello World!”:

$x = "Hello World!";
echo strrev($x);

Remove Whitespace

Whitespace refers to the spaces before and/or after the actual text, and you often want to remove this extra space.

Example

The trim() function removes any whitespace from the beginning and end of a string.

$x = " Hello World! ";
echo trim($x);

Convert String into Array

The PHP explode() function divides a string into an array.

The first parameter of the explode() function indicates the “separator,” which specifies the points at which to split the string.

Note: The separator is mandatory.

Example

Split the string into an array using the space character as the separator:

$x = "Hello World!";
$y = explode(" ", $x);
//Use the print_r() function to display the result:
print_r($y);
/*
Result:
Array ( [0] => Hello [1] => World! )
*/