PHP String functions with examples


<?php
Please find below string functions in daily use

//trim()
trim() : It removes all the whitespaces from both sides of a string,
ltrim() and rtrim() for removing them from only one side of the string (left or right).

//explode
It convert string to array based on comma, space etc…
Ex: echo explode(” “,$arr); // Array

//implode
It convert array to string
Ex: echo implode(” “,$arr); // String

//str_replace
It’s used for replace word
Ex: echo str_replace(“world”,”Peter”,”Hello world!”);
//world replaced with peter

//preg_replace
Perform a regular expression search and replace
Ex: $str = preg_replace(‘/\s+/’, ”, $str);
// But if it could be due to space, tab…you can use

//md5
It encode’s the string

//str_split
Splits a string into an array

//strcmp
Compares two strings (case-sensitive) returns ‘0’ when true.

 

we are having lot of string functions please find below URL….

http://www.w3schools.com/php/php_ref_string.asp
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s