Pattern matching for ASC 0 character

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ProudCat
    New Member
    • Apr 2006
    • 4

    Pattern matching for ASC 0 character

    I need to parse/extract data out of string that is delimited by ASCII 0 character.
    When I try to use explode('0',$my data) it converts mydata to an array incorrectly.
    Some array elements are empty and some are split in the middle.
    I also tried str_replace('0' ,'#', $mydata) and preg_replace('0 ','#', $mydata) - they both do not work at all.

    It sounds like I have to parse string manually byte by byte myself. Is there any simple solution?

    Thanks,
    Jane
  • terralos
    New Member
    • Apr 2006
    • 3

    #2
    Don't know what you are using to parse, but try matching for when the character equals the constant NULL. You should also be able to do something like:
    =============== =======
    if (NextChar)
    move to next character;
    else
    delimiter has been reached;
    =============== =======

    When NextChar becomes the ascii value of NULL, the if statement will fail, and you know that you have reached your delimiter. BTW, where did you get a NULL delimited file?

    I am assuming you mean the ascii character whose binary value is 00000000 and not the ascii representation of the number zero. Hope I interpreted your question properly.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      It would be worth posting the input string and the incorrect output array and the required output.

      Comment

      • ProudCat
        New Member
        • Apr 2006
        • 4

        #4
        Folks,
        I've got the right answer from another forum.
        Solution is to use this:

        $str = preg_split('/\00/', $str);

        Thanks anyway.
        Jane

        Comment

        Working...