473,480 Members | 1,836 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

String comparison problem...

cjl
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_contents('./dicomdir');

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

while (count($myList[0])) {
$substr = array_shift($myList[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.3680043.2.287.192.168.1.3.3346521.9841 87648748.32768
1.2.840.10008.1.2.1
1.2.826.0.1.3680043.2.287.0.113
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_contents('./dicomdir');

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

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

This does not work as expected. Any ideas?

-cjl

Jul 17 '05 #1
3 1708
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from cjl
contained the following:

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

This does not work as expected. Any ideas?


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/
Jul 17 '05 #2
cjl
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

Jul 17 '05 #3
I noticed that Message-ID:
<11**********************@l41g2000cwc.googlegroups .com> from cjl
contained the following:
Learning PHP is fun...thanks again for the help...I guess I should go
read about trim().

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/
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2528
by: Neil Zanella | last post by:
Hello, Consider the following program. There are two C style string stack variables and one C style string heap variable. The compiler may or may not optimize the space taken up by the two stack...
51
8205
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct...
46
5089
by: yadurajj | last post by:
Hello i am newbie trying to learn C..I need to know about string comparisons in C, without using a library function,...recently I was asked this in an interview..I can write a small program but I...
4
2262
by: Dim | last post by:
I found that C# has some buggy ways to process string across methods. I have a class with on global string var and a method where i add / remove from this string Consider it a buffer... with some...
19
9482
by: David zhu | last post by:
I've got different result when comparing two strings using "==" and string.Compare(). The two strings seems to have same value "1202002" in the quick watch, and both have the same length 7 which I...
5
14901
by: BILL | last post by:
Hi Everyone, I've been looking through these .NET groups and can't find the exact answer I want, so I'm asking. Can someone let me know the best way (you feel) to search a C# string for an...
5
657
by: MaSTeR | last post by:
Can anyone provide a practical short example of why in C# I shouldn't compare two strings with == ? If I write this in JAVA String string1 = "Widget"; if (string1 == "Widget") ...
26
3765
by: Neville Lang | last post by:
Hi all, I am having a memory blank at the moment. I have been writing in C# for a number of years and now need to do something in VB.NET, so forgive me such a primitive question. In C#, I...
12
2461
by: ujjc001 | last post by:
Here's one for ya. I want to create a relational operator from a string object, i.e. I want to somehow be able to say: string opString = ">="; int i1 = "20"; int i2 = "10"; if (i1...
6
4330
by: aznimah | last post by:
hi, i'm work on image comparison. i'm using the similarity measurement which i need to: 1) convert the image into the binary form since the algorithm that i've use works with binary data for the...
0
7054
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6918
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...
0
7102
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6756
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4798
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4495
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
570
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.