Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing 2 string

Status
Not open for further replies.

JJJ777

Programmer
Jun 5, 2002
33
0
0
MY
hi all...
need help urgent....

i have 2 string stored in different field.
so i need to campare both string ..
let say $string1 = "ABCDABCD";
$string2 = "AAAAAAAA";

i use substr to compare it but it was very slow to compare about 15000 data..so could anyone suggest me other way..

below is my code.

for($i=0;$i<$total;$i++) {
$skema1=substr($skema,$i,1);

$obj_result1=substr($obj_result,$i,1);
if($skema1==$obj_result1){

$query1=&quot;update peperiksaan set obj_markah=obj_markah+1 where nokp='$nokp'&quot;;
$result1=pg_exec($link_id,$query1);
// echo &quot;$obj_markah<br>&quot;;
}
}
}

$query1=&quot;update peperiksaan set marked='yes' where nokp='$nokp'&quot;;
$result1 = pg_exec($link_id,$query1);

}
 
Check out this! I did not understand why you compare the 2 strings. But I hope this will help you. I you can check out thisone I might go faster!

When you need a first element (or another one you know the position of) you can do this:

$str = 'Maxim Maletsky';
echo '
The first letter of my name is (' . $str[0] . ')';

// This prints:
// First letter of my name is (M)
//
// This example is the same as substr($str, 0, 1);

---

// Now, the same thing is when you need to find out the last letter:

echo '
The last letter of my name is (' . $str[strlen($str)-1] . ')';

// This prints:
// First letter of my name is (y)
//
// This example is the same as substr($str, -1);

---

This example can explain it better:

for($i=0; $i<strlen($str); $i++) {
echo &quot;
Character [$i] is (&quot; . $str[$i] . &quot;)&quot;;
}

Using this instead of substring might help you a bit not to create too many confusion.


Some help goes to Maxim! :)
 
It all depends of whay you want your string comparison to yield.
Do you just want to see if the strings are the same or different?
Do you want to find out the parts that are different?

If you tell us the details, we'll be able to give more meaningful answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top