View your Shopping CartFrequently Asked QuestionsEmail Us
Home | About Us | Contact Us
SmartWebby.com provides best web design & web programming services globally
We specialize in Rapid Web Design, ASP.net, ASP and PHP web programmingBest Web Design, Best Web Programming, Global Service Provider - Dependable Professionals to build your website right!

PHP String Functions

In this tutorial you will learn about some common string functions in PHP. This includes:

  1. Length of a string
  2. Splitting the string into an array
  3. Joining array elements into a single string
  4. Repeat the similar string into multiple times
  5. Remove the HTML tags from a string

1. Length of a string

The function 'strlen' is used to return the length of the string that is passed as an argument.

Syntax:

strlen(stringname);

Example:

$string="Baskar";

strlen($string); Output : 6

2. Splitting a string into an array

The function 'explode' is used to split a string into an array using a separator. It takes the separator and the string as its argument.

Syntax:

explode(separator,stringname);

Example:

$string="11-02-2005"

explode("-",$string); Output : 11 in array[0] , 02 in array[1] , 2005 in array[2]

3. Joining the array elements into a single string

The function 'join' is used to join various array elements into a single string. Alternatively 'implode' can also be used to join array elements into a string.

Syntax:

join(separator,arrayname);
(or)
implode(separator,arrayname);

Example:

$arraystring=array("s","baskar","shun");

implode("/",$arraystring); Output : s/baskar/shun

4. Repeating a string 'n' times

The function 'str_repeat' is used to repeat a given string 'n' times. The function takes the string and the number of times to be repeated as its argument.

Syntax:

str_repeat($string,integervalue);

Example:

str_repeat("dd",3); Output : dddddd

5. Remove HTML tags from the string

The function 'strip_tags' is used to remove the HTML tags present in a string by taking the string as its argument.

Syntax:

strip_tags($string);

Example:

strip_tags("Baskar s <br> Name",3); Output : Baskar S Name

That' it you've learnt about some common string functions used in PHP.

Absolutely FREE Web Templates
Check out these quality free web templates and download them without any registration or sign-up!

FREE Web Design Guide
From web design tips & ideas to HTML, CSS Styles, Fireworks & Dreamweaver you'll find all you need to know about effective web site design right here!

Quality Dreamweaver Templates
Professional quality dreamweaver templates in over 20 categories, starting at just $9.95! Instant download & easy customization