473,386 Members | 1,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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>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
2 3315
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chris | last post by:
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 =...
6
by: Marco Chiarandini | last post by:
Dear all, I am experiencing a problem in the deallocation of STL data structures. In paritcular I create a vector of sets and insert integers in each set. I do not define any deallocator since...
12
by: Lars Langer | last post by:
Hi there, I'm new to this C - never the less - I'm trying to search a string for the occurence of a substring - However, I'm not very succesful since my use of the strstr function always returns...
4
by: Hugh | last post by:
Hello, I am having some problems understanding (most likely), parsing a text file. I would like to parse a file like: block1 { stuff; ... stuffN; };
24
by: John Smith | last post by:
How to test whether strstr() returns a null pointer or not? Do I use something like the following? if(NULL != strstr(str1,str2)) That does not seem to work.
5
by: OzBob | last post by:
Am performing the following check to determine if a set of text is at the start of a string,.... /* Check for literal text DD at beginning of string date_format */ char date_format; if...
4
by: smnoff | last post by:
I am trying to use the strstr function but it doesn't seem to work with a dynamically allocated string that I pass into a function. Specifically, I am using a Macromedia C-level extensibility and...
13
by: Kelvin Moss | last post by:
Hi all, How could one write an strstr function to work with unicode characters? Are there existing implementations/solutions/api for doing so? Any pointers would be appreciated. Thanks ..
6
by: linq936 | last post by:
Hi, I have the following code: #include <stdio.h> int main(void){ char* str1 = "abc"; char* str2 = '\0'; if ( strstr(str1, str2) == NULL ){ printf("yes\n");
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.