Tuesday, May 22

PHP String Functions

STRING FUNCTIONS

Hi All,

I have added few important string functions. I hope it help you to understand and remember the string functions in PHP.

<?php

$str = "Welcome to Techie Snacks";
$str1 = "here you can find all the technical solutions across the platform";
$str2 = "\t\t New Era begins\t\t";

$email = "xxxx@gmail.com";


/*
  strtoupper
All characters of the String have Converted into UPPERCASE
Syntax: strtoupper($string);
*/


$upper = strtoupper($str);
echo $upper."</br>";


/*
strtolower
All characters of the String have Converted into LOWERCASE
Syntax: strtolower($string);
*/


$lower = strtolower($str);
echo $lower."</br>";


/*
ucfirst
First character of the word have Converted into UPPERCASE
Syntax: ucfirst($string);
*/


$ucupper = ucfirst($str1);
echo $ucupper."</br>";


/*
lcfirst
First character of the word have Converted into LOWERCASE
Syntax: lcfirst($string);
*/


$lcupper = lcfirst($str);
echo $lcupper."</br>";


/*
ucwords
First character of every word in UPPERCASE and all other characters remains unchanged.
Syntax: ucwords($string);
*/


$lcupper = ucwords($str1);
echo $lcupper."</br>";


/*
strlen
Returns and integer value representing the length of string.
It calculates the length of the string including all the whitespace and special characters.
Syntax: strlen($string)
*/


$strlength = strlen($str1);
echo $strlength."</br>";


/*
ltrim
Strip whitespace (or other characters) from the BEGINNING of a string
Syntax: string ltrim ( string $str [, string $character_mask ] );
*/


$ltrimmed = ltrim($str2,"\t");
echo $ltrimmed."</br>";


/*
trim
Strip whitespace (or other characters) from the BEGINNING and END of a string
Syntax: string trim ( string $str [, string $character_mask = " \t\n\r\0\x0B" ] );
*/


$trimmed = trim($str2, "e");
echo $trimmed."</br>";

/* strrev
Reverse a string
Syntax: strrev (string $string);
*/


$reverse = strrev($str);
echo $reverse."</br>";

/* strpos
Find the position of the first occurrence of a substring in a string
Syntax: int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] );
*/
$find   = 'a';
$strpos = strpos($str, $find);
echo $strpos."</br>";


/* strstr
Find the first occurrence of a string
Syntax: string strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] );
*/
$domain_name = strstr($email, '@');
echo $domain_name."</br>";


/* stristr
Find the first occurrence of a string using insensitive
Syntax: string strstr ( string $haystack , mixed $needle [, bool $before_needle = FALSE ] );
*/
$domain_name = stristr($str1, 'H');
echo $domain_name."</br>";

?>

OUTPUT:
WELCOME TO TECHIE SNACKS
welcome to techie snacks
Here you can find all the technical solutions across the platform
welcome to Techie Snacks
Here You Can Find All The Technical Solutions Across The Platform
65
New Era begins
New Era begins
skcanS eihceT ot emocleW
20
@gmail.com

here you can find all the technical solutions across the platform

No comments:

Post a Comment

Backup files to google drive using PHP coding

 Dear All, To backup files to Google Drive using PHP coding, you can use the Google Drive API and the Google Client Library for PHP. Here...