Problems with STRSTR function

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

    Problems with STRSTR function

    Applogies for repost. For some reason the second half of my message
    got chopped off... here's the full this agin (hopefully!)

    I'm having a problem with the strstr function that is driving me up
    the ?!**!?! wall!

    OK, I hope the following sample code will illustrate the problem.

    <?

    $exif = read_exif_data_ raw($HTTP_POST_ FILES['image']['tmp_name'],0);

    echo '<hr><b>Exampl e 1</b><br>This is the test using fields from the
    exif data<hr>';

    $make=$exif['IFD0']['Make'];
    $model=$exif['IFD0']['Model'];

    echo "$make<br>" ;
    echo "$model<br><br> ";

    if(stristr($mod el,$make))
    {
    echo "true<br><b r>";
    }
    else
    {
    echo "false<br><br>" ;
    }

    echo '<hr><b>Exampl e 2</b><br>This is the test using manual data<hr>';

    $make="Canon";
    $model="Canon EOS300D DIGITAL";

    echo "$make<br>" ;
    echo "$model<br><br> ";

    if(stristr($mod el,$make))
    {
    echo "true<br><b r>";
    }
    else
    {
    echo "false<br><br>" ;
    }

    ?>


    And here is the out put:

    Example 1
    This is the test using fields from the exif data
    Canon
    Canon EOS 300D DIGITAL

    false

    Example 2
    This is the test using manual data
    Canon
    Canon EOS300D DIGITAL

    true

    This is some code called by a form that uploads an image. In the first
    example I am reading in two variables from the EXIF data using a
    function from http://www.offsky.com/software/exif/index.php. I am then
    comparing the contents of the two fields. the first field contains
    "Canon" (in the variable $make) and the second contains "Canon EOS300D
    DIGITAL" (in the variable $model). But for some reason it returns
    false. In the second example I am entering exactly the same data into
    the $make and $model variables manually. This time true is return as
    expected. The echo statements confirm that the $make and $model
    variable contain the same data in both examples. Can anyone offer an
    explanation/solution and save my sanity??

    Thanks in advance, Chris
  • Herb Kauhry

    #2
    Re: Problems with STRSTR function

    Probably a ASCII nul character (0) terminating the string stored in $make
    (or possibly #x160)

    --

    "Chris" <cjas@blueyonde r.co.uk> wrote in message
    news:b71c3a04.0 312080728.62ec8 731@posting.goo gle.com...[color=blue]
    > Applogies for repost. For some reason the second half of my message
    > got chopped off... here's the full this agin (hopefully!)
    >
    > I'm having a problem with the strstr function that is driving me up
    > the ?!**!?! wall!
    >
    > OK, I hope the following sample code will illustrate the problem.
    >
    > <?
    >
    > $exif = read_exif_data_ raw($HTTP_POST_ FILES['image']['tmp_name'],0);
    >
    > echo '<hr><b>Exampl e 1</b><br>This is the test using fields from the
    > exif data<hr>';
    >
    > $make=$exif['IFD0']['Make'];
    > $model=$exif['IFD0']['Model'];
    >
    > echo "$make<br>" ;
    > echo "$model<br><br> ";
    >
    > if(stristr($mod el,$make))
    > {
    > echo "true<br><b r>";
    > }
    > else
    > {
    > echo "false<br><br>" ;
    > }
    >
    > echo '<hr><b>Exampl e 2</b><br>This is the test using manual data<hr>';
    >
    > $make="Canon";
    > $model="Canon EOS300D DIGITAL";
    >
    > echo "$make<br>" ;
    > echo "$model<br><br> ";
    >
    > if(stristr($mod el,$make))
    > {
    > echo "true<br><b r>";
    > }
    > else
    > {
    > echo "false<br><br>" ;
    > }
    >
    > ?>
    >
    >
    > And here is the out put:
    >
    > Example 1
    > This is the test using fields from the exif data
    > Canon
    > Canon EOS 300D DIGITAL
    >
    > false
    >
    > Example 2
    > This is the test using manual data
    > Canon
    > Canon EOS300D DIGITAL
    >
    > true
    >
    > This is some code called by a form that uploads an image. In the first
    > example I am reading in two variables from the EXIF data using a
    > function from http://www.offsky.com/software/exif/index.php. I am then
    > comparing the contents of the two fields. the first field contains
    > "Canon" (in the variable $make) and the second contains "Canon EOS300D
    > DIGITAL" (in the variable $model). But for some reason it returns
    > false. In the second example I am entering exactly the same data into
    > the $make and $model variables manually. This time true is return as
    > expected. The echo statements confirm that the $make and $model
    > variable contain the same data in both examples. Can anyone offer an
    > explanation/solution and save my sanity??
    >
    > Thanks in advance, Chris[/color]


    Comment

    • Chung Leong

      #3
      Re: Problems with STRSTR function

      My guess is that the data is stored as Unicode-16. Do a strlen() on $make
      and $model and see if they're not longer than you expected.

      Uzytkownik "Chris" <cjas@blueyonde r.co.uk> napisal w wiadomosci
      news:b71c3a04.0 312080728.62ec8 731@posting.goo gle.com...[color=blue]
      > Applogies for repost. For some reason the second half of my message
      > got chopped off... here's the full this agin (hopefully!)
      >
      > I'm having a problem with the strstr function that is driving me up
      > the ?!**!?! wall!
      >
      > OK, I hope the following sample code will illustrate the problem.
      >
      > <?
      >
      > $exif = read_exif_data_ raw($HTTP_POST_ FILES['image']['tmp_name'],0);
      >
      > echo '<hr><b>Exampl e 1</b><br>This is the test using fields from the
      > exif data<hr>';
      >
      > $make=$exif['IFD0']['Make'];
      > $model=$exif['IFD0']['Model'];
      >
      > echo "$make<br>" ;
      > echo "$model<br><br> ";
      >
      > if(stristr($mod el,$make))
      > {
      > echo "true<br><b r>";
      > }
      > else
      > {
      > echo "false<br><br>" ;
      > }
      >
      > echo '<hr><b>Exampl e 2</b><br>This is the test using manual data<hr>';
      >
      > $make="Canon";
      > $model="Canon EOS300D DIGITAL";
      >
      > echo "$make<br>" ;
      > echo "$model<br><br> ";
      >
      > if(stristr($mod el,$make))
      > {
      > echo "true<br><b r>";
      > }
      > else
      > {
      > echo "false<br><br>" ;
      > }
      >
      > ?>
      >
      >
      > And here is the out put:
      >
      > Example 1
      > This is the test using fields from the exif data
      > Canon
      > Canon EOS 300D DIGITAL
      >
      > false
      >
      > Example 2
      > This is the test using manual data
      > Canon
      > Canon EOS300D DIGITAL
      >
      > true
      >
      > This is some code called by a form that uploads an image. In the first
      > example I am reading in two variables from the EXIF data using a
      > function from http://www.offsky.com/software/exif/index.php. I am then
      > comparing the contents of the two fields. the first field contains
      > "Canon" (in the variable $make) and the second contains "Canon EOS300D
      > DIGITAL" (in the variable $model). But for some reason it returns
      > false. In the second example I am entering exactly the same data into
      > the $make and $model variables manually. This time true is return as
      > expected. The echo statements confirm that the $make and $model
      > variable contain the same data in both examples. Can anyone offer an
      > explanation/solution and save my sanity??
      >
      > Thanks in advance, Chris[/color]


      Comment

      Working...