473,545 Members | 2,697 Online
Bytes | Software Development & Data Engineering Community
+ 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_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

Jul 17 '05 #1
3 1715
I noticed that Message-ID:
<11************ **********@o13g 2000cwo.googleg roups.com> from cjl
contained the following:

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?


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************ **********@l41g 2000cwc.googleg roups.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
2536
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 variables by placing them at the same address (my g++ compiler does this). Therefore the output of the given C program is compiler dependent. What...
51
8226
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 code? many thx!
46
5104
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 was told that wouldn't it be wise to first get the length of the strings..if it doesn't match then they are not the same..I agreed...then he...
4
2265
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 values and separators class { private string globalvar = ""; private void manipulate (whattodo ) //substring, join, etc....
19
9491
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 have tried to print out by debug.writeline(). But the "==" operator results false, and string.Compare() results true. Somebody helps me!
5
14903
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 occurance of a CASE INSENSITIVE substring, returning the found position. I'm speaking of larger strings to search as well ~50K-500K. Here's what I...
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") System.Console.WriteLine("String1 Equal.");
26
3786
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 test whether a string has a value or not by the following syntax: if (thisString.Trim() == "") {
12
2468
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 somemethodhere(opString) i2) { //do the true here } else {
6
4331
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 computation 2) compare the string binary data to get the similarity or dissimilarity result. The problem is, i already done with the image (jpg)...
0
7434
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7692
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7457
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7791
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5078
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1921
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
744
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.