PHP String Functions

PHP is equally powerful than any other server side scripting languages in handling strings. We will experiment with some of the string functions of PHP with some examples. There are powerful functions like regular expressions to manage complex string handling requirements. Here are some of them.
Functions Description
preg_replace()regular expression string replacement

Displaying html tags

To display html tags on web pages we have to use htmlspcialchars function

String encryption

We can use md5 php function to encrypt strings to make it secure.

Converting line breaks

We can use nl2br function to take care of line breaks while displaying in web pages.

Random string

We can generate random string by using rand function

Removing html tags

We can use strip_tags function to remove html tags from a string and extract the text part.

Replacing part of a string

All presence of a searching string can be replaced by using str_replace function, this is case sensitive

Case in-sensitive string replacement

We can use case in-sensitive string replacement by using str_ireplace function.

Length of the String

By using strlen function in PHP we can calculate length of the string

PHP string reverse

We can reverse a string by using strrev function

String search

Searching for a string inside main string

Breaking string

We can create an array by breaking a string using split command

Getting a sub string

We can generate a substring from our main string by using substr command

Removing chars from end

Remove chars from end of the string by using length and sub string functions

Counting occurrence of substring

Calculating number of times a substring is present inside a main string

Repeating a string

Specify number of times a string has to repeat

Case change of a string

We can change from lower to upper and upper to lower case chars of a string

String comparison

PHP string comparison function

Case sensitive string comparison

A case sensitive string comparison can be done by using strcmp function

Padding from left or right of a string

We can pad strings from left or right or from both sides.

Removing blank space

We can remove blank space from left or right of a string

Making first char to uppercase

The first character of sting can be made upper case by using ucwords

getting csv data

Collecting array of records from CSV file by using file pointer.

writing csv data

Storing data from array or database table in a CSV file.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
Visitors Rating
Your Rating


PHP String Functions


Its good information

Post Comment This is for short comments only. Use the forum for more discussions.

Subscribe to our mailing list

* indicates required
Subscribe to plus2net
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us
©2000-2017 All rights reserved worldwide Privacy Policy Disclaimer