Results 1 to 4 of 4

Thread: how to split the string in 2 parts

  1. #1
    Join Date
    Oct 2008
    Posts
    40
    Thanks
    3
    Thanked 1 Time in 1 Post

    Smile how to split the string in 2 parts

    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<< / >> / << ddd
    output:-
    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[b ]/ <[/b] (There is space between / and >)

    i 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.

    Consider first appearance of separator to divide the string into two part

    So please tell me how to do this . is there any inbuilt function available in php?

    ...........................................
    Last edited by pankaj.ghadge; 11-12-2008 at 08:48 AM.

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I have been looking, but not that I can see. I was thinking there might be something listed under preg_split() in php.net, but I couldn't find anything.

    Maybe you could explode the $string and then implode it back together without string[0] and then put the two parts into a new array.
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Oct 2008
    Posts
    40
    Thanks
    3
    Thanked 1 Time in 1 Post

    Smile

    CODE
    Code:
    $s1 = '10:16:52 10999_aa@mydomain.com/jsjac_simpleclient -> 10999_cc@mydomain.com/ > hi cc sds ds s sdsdsd s s sds';
    $s2 = '2008-11-11 16:21:59 10999_aa@mydomain.com/jsjac_simpleclient -> 10999_cc@mydomain.com/ < hi1234 / > / > / <';
    $htmlbits = preg_split('/(\/ >)|(\/ <)/',$s2,2); // or  $str_array = preg_split('/\/ [<>]/', $s1, 2);
    
    print_r($str_array);
    echo "<br>";
    print_r($htmlbits);

  4. The Following User Says Thank You to pankaj.ghadge For This Useful Post:

    james438 (11-13-2008)

  5. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Woot! not that I had the problem, but thanks for that answer. The answer was staring me right in the face and I just didn't see it. I think it was because I was reading more on the syntax as opposed to the preg_replace page at php.net.
    To choose the lesser of two evils is still to choose evil. My personal site

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •