By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,661 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,661 IT Pros & Developers. It's quick & easy.

Problems with STRSTR function

P: n/a
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>Example 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($model,$make))
{
echo "true<br><br>";
}
else
{
echo "false<br><br>";
}

echo '<hr><b>Example 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($model,$make))
{
echo "true<br><br>";
}
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


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

--

"Chris" <cj**@blueyonder.co.uk> wrote in message
news:b7**************************@posting.google.c om...
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>Example 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($model,$make))
{
echo "true<br><br>";
}
else
{
echo "false<br><br>";
}

echo '<hr><b>Example 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($model,$make))
{
echo "true<br><br>";
}
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

Jul 17 '05 #2

P: n/a
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" <cj**@blueyonder.co.uk> napisal w wiadomosci
news:b7**************************@posting.google.c om...
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>Example 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($model,$make))
{
echo "true<br><br>";
}
else
{
echo "false<br><br>";
}

echo '<hr><b>Example 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($model,$make))
{
echo "true<br><br>";
}
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

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.