Jump to content

strtolower($a)==strtolower($b)!=match!?!? Me == WTF!?


Jerred121

Recommended Posts

OK, i have a function that compares values and returns the results, regardless of case, ie: Interfacility Transfer = INTERFACILITY TRANSFER here is the function:

 

    function fncResult ($expVal, $actVal)
    {
        $negNulls=array("-5","-10","-15","-20","-25");
        if (!in_array($expVal, $negNulls))
        {
            if(strtolower($expVal)==strtolower($actVal))
            {
                echo "
                <td class='match' title='The values match.'>Match</td>
            </tr>";
            }
            else
            {
                echo "
                                <td class='notMatch'  title='The values do not match.'>Not Match<br />No Match</td>
                            </tr>";
            }
        }
        else
        {
            echo "
                <td class='null'  title='The value in the XML was a negative null.'>Negative Null</td>
            </tr>";
        }
    }

It works about 99% of the time except when it comes to this:

//--Type of service requested
        echo "
            <tr>
                <td>E02_04</td>
                <td>Type of Service Requested</td>
                <td>36. <Nature of Call></td>
                <td>$fldServReq</td>
                <td>".fncGrabNemsis("E02_04",$fldServReq,$local)."</td>
                <td>".fncIsSet($CZ_E02_04[1])."</td>";
        fncResult(fncGrabNemsis("E02_04",$fldServReq,$local),fncIsSet($CZ_E02_04[1]));

Although it looks more complicated, it really is just a strtolower($expVal)==strtolower($actVal), comparison.  When I echo the values being compared, I get: "interfacility transfer" and "interfacility transfer" and "No Match"... WTF?  Could it be because the first value is coming from a XML (UTF-8) and the second is from a DB (?) Edit: NM, that can't be the problem.

 

I have no idea what to do and am incredibly frustrated since this a simple task.  Thanks for any help!

Link to comment
https://forums.phpfreaks.com/topic/226991-strtolowerastrtolowerbmatch-me-wtf/
Share on other sites

Look at the HTML code. Are there any leading/trailing spaces or other white-space characters. Is the space in one value the space character and an   in the other?

 

Also, if you are comparing strings you can use strcasecmp() to do a case-insensitive comparison without using strtolower().

 

Try the following to see what you get

    function fncResult ($expVal, $actVal)
    {
        //Set default values
        $class = 'null';
        $title = 'The value in the XML was a negative null.';
        $text  = 'Negative Null';
        //
        $negNulls=array("-5","-10","-15","-20","-25");
        if (!in_array($expVal, $negNulls))
        {
            if(strcasecmp($expVal, $actVal)===0)
            {
                $class = 'match';
                $title = 'The values match';
                $text  = 'Match';
            }
            else
            {
                $class = 'notMatch';
                $title = 'The values do not match.';
                $text  = 'No Match: expVal: ['.htmlspecialchars($expVal).'], actVal: ['.htmlspecialchars($actVal).']';
            }
        }
        echo "<td class=\"{$class}\"  title=\"{$title}\">{$text}</td>\n";
        echo "</tr>\n";
    }

strcasecmp returned even worse results (it failed on all my ints) here is what the html looks like:

            <tr>
                <td>E02_04</td>
                <td>Type of Service Requested</td>
                <td>36. <Nature of Call></td>

                <td>40</td>
                <td>Interfacility Transfer</td>
                <td>INTERFACILITY TRANSFER</td>
                <td class='notMatch'  title='The values do not match.'>Not Match<br />interfacility transfer
<br />interfacility transfer</td>
                            </tr>

No extra spaces...

Here is a table of my output:

           

               

Element

               

Element Name

               

CZ Field

               

XML Value

 

               

Expected Value

               

Actual Value

               

Result

           

           

 

               

E02_02

               

Incident ID

               

1. Dispatch #

               

100001

               

100001

               

100001

 

               

Match

           

           

               

E02_04

               

Type of Service Requested

               

36. <Nature of Call>

 

               

40

               

Interfacility Transfer

               

INTERFACILITY TRANSFER

                               

Not Match,interfacility transfer

,interfacility transfer

                           

           

 

               

E02_11

               

EMS Unit/Vehicle  Number

               

17. Unit #

               

-20

               

-20

               

UNIT 400

 

               

Negative Null

           

           

               

E02_17

               

On Scene Odometer Reading  of Responding  Vehicle

               

29. Loaded Miles

               

310323.0

 

               

7 (Loaded Miles)

               

7.00

               

Match

           

           

               

E02_18

               

Patient Destination Odometer Reading of Responding  Vehicle

 

               

29. Loaded Miles

               

310330.0

               

7 (Loaded Miles)

               

7.00

               

Match

           

 

           

               

E03_01

               

Complaint Reported  by Dispatch

               

35. <Chief Complaint>

               

400

               

Abdominal Pain

 

               

ABDOMINAL PAIN

                               

Not Match,abdominal pain

,abdominal pain

                           

           

               

E04_01[1]

               

Medic ID 1

 

               

37. <Interventions>

               

1918

               

1918

               

1918

               

Match

           

 

           

               

E04_01[2]

               

Medic ID 2

               

37. <Interventions>

               

3110

               

3110

 

               

3110

               

Match

           

           

               

E04_01[3]

               

Medic ID 3

               

37. <Interventions>

 

               

RN142192

               

RN142192

               

RN142192

               

Match

           

           

               

E05_02

 

               

PSAP Call Date/Time

               

30. <Dispatch Info>

               

Array

               

To Be Filled

               

To Be Filled!

                               

Not Match,to be filled,to be filled!

 

                           

           

               

E05_09

               

Unit Left Scene Date/Time

               

2. Incident Date

               

2011-01-10T08:30:00.0Z

               

2011-01-10T08:30:00.0Z

 

               

2011-01-10

                               

Not Match,2011-01-10t08:30:00.0z,2011-01-10

                           

           

               

E06_01

               

Last Name

 

               

5. Last Name

               

Patient1

               

Patient1

               

PATIENT1

               

Match

           

 

           

               

E06_02

               

First Name

               

3. First Name

               

Test1

               

Test1

 

               

TEST1

               

Match

           

           

               

E06_03 

               

Middle Name

 

               

4. Middle Name

               

M

               

M

               

M

               

Match

 

           

           

               

E06_04

               

Patient's Home Address

               

10. Address 1

               

123 Fake ST

 

               

123 Fake ST

               

123 Fake ST

               

Match

           

       

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.