
11-09-2007, 05:34 AM
|
| D-Web Sr.Programmer | | Join Date: Mar 2007
Posts: 118
| |
Re: string functions and manipulations in php Quote:
Originally Posted by Anand 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 |