View Single Post
  #59 (permalink)  
Old 11-09-2007, 05:34 AM
venkat_charya venkat_charya is offline
D-Web Sr.Programmer
 
Join Date: Mar 2007
Posts: 118
venkat_charya is on a distinguished road
Thumbs up Re: string functions and manipulations in php

Quote:
Originally Posted by Anand View Post
Hi venkatcharya,

Can you please provide the scenarios under what circumstances we need to use the explode and split functions in PHP. Which one is better in considering the performance.

Hi Anand,

Both are useful as per the scenario and requirment. For example if you have string like "Hello Computer World" and you want to convert this as array then it would be preferable that you use "explode" because there is only one delimeter here called "space".

PHP Code:
$aArr explode(" ",$vString); 
But if you have date string which may contain dynamic delimeter like "\,-,." then split is only the option to solve your problem.

PHP Code:
<?php
// Delimiters may be slash, dot, or hyphen
$date "04/30/1973";
list(
$month$day$year) = split('[/.-]'$date);
echo 
"Month: $month; Day: $day; Year: $year<br />\n";
?>
Thanks
__________________
K K Venkata Charya
Success is easy to get but difficult to retain
Reply With Quote