SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

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.

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

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

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked

Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
PHP Tutorials
String Functions
PHP Monthly Planner
PHP Introduction
Loops & structure
Array
Date & Time
Functions
Form Handling
File Handling
Math Functions
String Functions
GD Functions
Comment Posting
Content Management
PHP & Ajax
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.