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
    New Coder
    Join Date
    Nov 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Interesting SPLIT problem

    I have a simple problem that is boggling my mind.

    Lets say I have a varable like this:

    PHP Code:
    $var1 ='"THIS IS A TEST OF THE EMERGENCY$TESTVAR BRODCAST SYSTEM'
    Now I want it to split it right before the $TESTVAR so i get an output of:

    PHP Code:
    $outputvar[0//should equal "THIS IS A TEST OF THE EMERGENCY"
    $outputvar[1// should equal "$TESTVAR BROADCAST SYSTEM" 
    However when I do a:

    PHP Code:
    split('$TESTVAR',$var1); 
    I Get:

    PHP Code:
    $outputvar[0// equals "THIS IS A TEST OF THE EMERGENCY $TESTVAR"
    $outputvar[1// equals " BROADCAST SYSTEM" 
    So basically i want to split before my designated expression.

    Make any sense? Any ideas?

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $var1 ='"THIS IS A TEST OF THE EMERGENCY$TESTVAR BRODCAST 
    SYSTEM'
    ;
    $array1=explode('$',$var1);
    $array2=array($array1[0], '$'.$array1[1]); 
    is one of the many way to so this. You could also search for the position and then make two substring.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #3
    New Coder
    Join Date
    Nov 2002
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help. With a little tweaking I was able to tailor it for my needs and its working perfect. Thank you very much.


  •  

    Posting Permissions

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