PHP-String functions


PHP-String functions

PHP-String functions:

  1. strtolower()-Converts a string to lowercase letters
  2. strtoupper()-Converts a string to uppercase letters
  3. str_replace- Used to locate and replace specified string values in a given string. The function accepts three arguments. The first argument is the text to be replaced, the second argument is the replacement text and the third argument is the text that is analyzed.
  4. substr()-Returns a part of a string- Used to return part of the string. It accepts three (3) basic parameters. The first one is the string to be shortened, the second parameter is the position of the starting point, and the third parameter is the number of characters to be returned.

Example:

$str = "I Section Rocks Always!<br>";

$str = strtolower($str);

echo $str;

output: //I section rocks always!

Example:

$str = "I Section Rocks Always!<br>";

$str = strtoupper($str);

echo $str;

output: I SECTION ROCKS ALWAYS!

Example:

echo str_replace ('the', 'that', 'the laptop is very expensive');

output:that laptop is very expensive

Example:

$my_var = 'This is a really long sentence that I wish to cut short';

echo substr($my_var,0, 12);

output: This is a re

Custom Search

%d bloggers like this: