String comparison problem...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cjl

    String comparison problem...

    Hey all:

    Just started playing with PHP, and ran into a little problem. I'm
    writing a script that will extract the strings from a binary file, then
    parse through them and extract information:

    <?php

    $data = file_get_conten ts('./dicomdir');

    preg_match_all( '/[\x20-x7f]{4,}/', $data, $myList);

    while (count($myList[0])) {
    $substr = array_shift($my List[0]);
    print $substr . "\n";
    }
    ?>

    This works fine, and basically emulates the "strings" command from the
    binutils package. Sample output in my test case:

    DICM
    1.2.840.10008.1 .3.10
    1.2.826.0.1.368 0043.2.287.192. 168.1.3.3346521 .984187648748.3 2768
    1.2.840.10008.1 .2.1
    1.2.826.0.1.368 0043.2.287.0.11 3
    SHS_MV300_VA30A
    PACSCUBE
    PACSCUBE MEDIA
    PATIENT
    DOE-^JANE
    68682
    19340928

    I want to look for the word 'PATIENT', the assign the next word to a
    variable, so I tried this:

    <?php

    $data = file_get_conten ts('./dicomdir');

    preg_match_all( '/[\x20-x7f]{4,}/', $data, $myList);

    while (count($myList[0])) {
    $substr = array_shift($my List[0]);
    if ($substr == 'PATIENT'){
    $patient_name = array_shift($my List[0]);
    print $patient_name;
    }
    }
    ?>

    This does not work as expected. Any ideas?

    -cjl

  • Geoff Berrow

    #2
    Re: String comparison problem...

    I noticed that Message-ID:
    <1111362553.599 458.150030@o13g 2000cwo.googleg roups.com> from cjl
    contained the following:
    [color=blue]
    >
    >while (count($myList[0])) {
    > $substr = array_shift($my List[0]);
    > if ($substr == 'PATIENT'){
    > $patient_name = array_shift($my List[0]);
    > print $patient_name;
    > }
    > }
    >?>
    >
    >This does not work as expected. Any ideas?[/color]

    Well why not tell us what it /is/ doing?

    Guessing...

    if(trim($substr )=='PATIENT'){ ...

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    • cjl

      #3
      Re: String comparison problem...

      Geoff:

      That did it, thank you!

      Of course, I fogot to tell you that it wasn't outputting anything
      before the fix.

      Learning PHP is fun...thanks again for the help...I guess I should go
      read about trim().

      -cjl

      Comment

      • Geoff Berrow

        #4
        Re: String comparison problem...

        I noticed that Message-ID:
        <1111363454.523 211.102020@l41g 2000cwc.googleg roups.com> from cjl
        contained the following:
        [color=blue]
        >Learning PHP is fun...thanks again for the help...I guess I should go
        >read about trim().[/color]


        That's what the manual is for. :-) It is important to know why
        something doesn't work.
        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        Working...