pankaj.ghadge Posted November 12, 2008 Share Posted November 12, 2008 hello , I want split the string into 2 parts.e.g 1)10:16:5210999_aa@mydomain.com/jsjac_simpleclient -> 10999_cc/ > hi cc sds ds s / > sdsdsd / > s s sds <Output:- str_array[0]=10:16:5210999_aa@mydomain.com/jsjac_simpleclient -> 10999_cc str_array[1]=hi cc sds ds s / > sdsdsd / >s s sds <2)10:17:31 10999_cc/jsjac_simpleclient ->10999_aa/ < d dd ddd<< / >> / << dddoutput:- str_array[0]=10:17:31 10999_cc/jsjac_simpleclient ->10999_aa str_array[1]=d dd ddd<< / >> / << ddd I want to split the string into two part by using separator / > or/ < (There is space between / and >)Consider first appearance of separator to divide the string into two parti want divide the string only into two part , but other function available in php divides the string into several part if it found separator character. So please tell me how to do this . is there any inbuilt function available in php?........................................... Link to comment Share on other sites More sharing options...
jlhaslip Posted November 12, 2008 Share Posted November 12, 2008 explode() will do that. But I don't see where it might work if there are several of the divider characters in the String.And what are the rules about which one to use. Your examples are unclear. Link to comment Share on other sites More sharing options...
pankaj.ghadge Posted November 12, 2008 Author Share Posted November 12, 2008 I have edited the example please take a look ................. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 12, 2008 Share Posted November 12, 2008 http://ca3.php.net/explodeyou may need to specify the leading space in the explode string since the '->' may affect the splitting of the original sting. There is a Limit clause for the explode as well. Link to comment Share on other sites More sharing options...
Jesdisciple Posted November 12, 2008 Share Posted November 12, 2008 You can also specify a limit in preg_split, which might be faster than two calls to strpos and one to explode. $str_array = preg_split('/\/ [<>]/', $str, 2); Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.