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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts

    correct way to split a string (need number before &) eg: 12&image.png

    hi,

    i have a string

    $str =12&image.png

    how do i get everything before the '&'

    the number of characters before the '&' is unknown.

    it can be 0, but not null.

    possible examples:

    $str = 0&blank.png
    $str = 2&hi.png
    $str = 3&black.png


    [edit]

    how about this:

    Code:
    $user_flag = substr($user_flag, 0, strpos($user_flag, '&') );
    Last edited by fatrat; 01-08-2007 at 10:30 PM.

  • #2
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    PHP Code:
    $user_flag=current(explode('&',$user_flag)); 
    is a bit shorter

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Posts
    127
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks for that, updating now


  •  

    Posting Permissions

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