Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: split string

  1. #1
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts

    split string

    how can i split a string based on a -

    i have a string as follows
    test-tester

    I want to return just test -- how can i do this?

  • #2
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    e.g.
    PHP Code:
    $str 'test-tester';

    $strArray explode('-',$str); // splits $str into an array: ['test']['tester']

    return $strArray[0]; // return the first item in the array 

  • #3
    Senior Coder
    Join Date
    May 2004
    Posts
    1,457
    Thanks
    15
    Thanked 0 Times in 0 Posts
    not working

    any idea?

    string is teh same before and after the split

  • #4
    Senior Coder
    Join Date
    Feb 2003
    Posts
    1,665
    Thanks
    0
    Thanked 27 Times in 25 Posts
    You said you wanted to return the first part of the string (split around -).
    The above code shows that you need to return $strArray[0], not $str.


  •  

    Posting Permissions

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