List Of PHP String Functions Programmer Need To Know

It our pleasure to share some best and useful resources, tutorials, inspiration stuff, development resources, design resources, etc. Today i have collected some useful stuff related to PHP programmers, few days ago we had provided some best websites to Learn PHP online and also today we come with some useful string functions for PHP. PHP is a widely used server-side scripting language that was basically designed for web applications. The most important thing is that its aopen source and cross-platform support language.

 

function- A block of code that can be executed whenever we need it. Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

Visit this list, i want share to you some useful string functions using PHP. i hope PHP programmers would love to use this article. Share your thought in our comment section below.

1) strtolower() :

This function is one of the most useful part of PHP functions, it helps you to change the case of all uppercase characters in the string to lowercase.

Sytax - strtolower(<string>);

 

Example – <?php echo strtolower(“HELLO WORLD”); ?> // Returns hello world

2) strtoupper() :

 

This function is is the most useful part of PHP functions, it helps you to change the case of all lowercase  characters in the string to uppercase.

Sytax - strtoupper(<string>);

Example – <?php echo strtolower(“hello world”); ?> // Returns HELLO WORLD

3) substr():

Its required a string, start, length(optional)

generic cialis no prescription

parameter. String- Specifies the string to return a part of. Start -

  • (!) A positive number – Start at a specified position in the string
  • (!!) A negative number – Start at a specified position from the end of the string
  • (!!!) 0 – Start at the first character in string
Length(optional) - Specifies the length of the returned string. Default is to the end of the string.

  • A positive number – The length to be returned from the start parameter
  • Negative number – The length to be returned from the end of the string

Syntax - substr(<string>,<start>,[<length>]);

4) strlen():

This function helps you to returns the length of the string.

Syntax: <?php echo strlen("Hello world");  ?> // Returns 11strlen(<string>);

 

5) ucfirst() :

It required string parameter, converts the first character of a string to uppercase.

Syntax - ucfirst(string)

Example -

<?php
echo ucfirst(“hello world”);
?>

Output – Hello world

6) str_replace():

Replaces some characters with some other characters in a string.

Syntax - str_replace(find,replace,string,count)

If the string to be searched is an array, it returns an array

A) If the string to be searched is an array, find and replace is performed with every array element

B) If both find and replace are arrays, and replace has fewer elements than find, an empty string will be used as replace

C) If find is an array and replace is a string, the replace string will be used for every find value

7) strcmp():

This function compares two strings.

Syntax: strcmp(string1,string2)

 

Example - <?php
echo strcmp(“Hello world!”,”Hello world!”);
?>

Output - 0

8) explode():

This function breaks the string into array on the basis of delimiter passed.

Syntax – explode(<delimeter>,<string>,[<limit>]);

Example -

<?php
$str = “Hello world. It’s a beautiful day.”;
print_r (explode(” “,$str));
?>

Output- Array
(
[0] => Hello
[1] => world.
[2] => It’s
[3] => a
[4] => beautiful
[5] => day.
)

9) implode():

The implode() function returns a string from the elements of an array.

Syntax: implode(separator,array)

 

Example - <?php
$arr = array(‘Hello’,'World!’,'Beautiful’,'Day!’);
echo implode(” “,$arr);
?>

Output - Hello World! Beautiful Day!

10) ucwords():

The ucwords() function converts the first character of each word in a string to uppercase.

Syntax: ucwords(string)

Example - <?php
echo ucwords(“hello world”);
?>

Output - Hello World

 


2 Comments

umashankar on February 11, 2012 at 5:34 pm.

Thanks for it:) helped me a lot.

Reply

Cliff Oliveira on February 13, 2012 at 2:29 pm.

Very good

Reply

Leave Your Comment

Your email will not be published or shared. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Google Analytics integration offered by Wordpress Google Analytics Plugin