Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

Split a string by string- using explode in php

Split a string by string

Syntax : array explode ( string $delimiter , string $string [, int $limit ] )

Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter .

Parameters :
delimiter : The boundary string.
String : The input string.
Limit : If limit is set, the returned array will contain a maximum of limit elements with the last element containing the rest of string .

If the limit parameter is negative, all components except the last -limit are returned.

Return Values :
If delimiter is an empty string (“”), explode() will return FALSE. If delimiter contains a value that is not contained in string , then explode() will return an array containing string

Example :

		<?php
		$rawPhoneNumber = "800-555-5555";
		$phoneChunks = explode("-", $rawPhoneNumber);
		echo "Raw Phone Number = $rawPhoneNumber <br />";
		echo "First chunk = $phoneChunks[0]<br />";
		echo "Second chunk = $phoneChunks[1]<br />";
		echo "Third Chunk chunk = $phoneChunks[2]";
		?>

Display:
Raw Phone Number = 800-555-5555
First chunk = 800
Second chunk = 555
Third Chunk chunk = 5555

Home

See the related posts

Mysql server version using php function – mysql_get_server_info()    Text file prompt download or force download using php    Number of lines in a file using php    Check Image exists or Not Using php and GD    PHP Warning: Call-time pass-by-reference has been deprecated   

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment