Okay, why not try somthing like this:
$string1 = "1,2,3,4,5,6,7,8";
$string2 = "2,4,6,8,10";
$ary1 = implode(",",$string1);
$ary2 = implode(",",$string2);
$num1 = '';
$num2 = '';
foreach($ary1 as $num){
$num1 .= $num;
}
foreach($ary2 as $num){
$num2 .= $num;
}
that would get the strings into "12345678" and "246810" respectfully, so you
could do simple add, subtract, greater than, less than, etc... hope this was
helpful.
Robert Keizer
""Richard Kurth"" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>I am trying to find out which string is the longest and then find out what
> is different between the two string. Sometimes String 2 is longer than
> String 1 The script below works sometimes but not all the time.
> Is there a better way to do this or tell me what is wrong with the script
> I
> am using
>
> $string1 = "1,2,3,4,5,6,7,8";
> $string2 = "1,2,3,4,6,7,8";
>
>
>
> function compare_by_length ($a, $b)
> {
> $la = strlen ($a);
> $lb = strlen ($b);
> if ($la == $lb) return (0);
> return ($a > $b) ? 1 : 2;
> }
>
> $string1 = "1,2,3,4,5,6,7,8";
> $string2 = "1,2,3,4,6,7,8";
>
> $longstring=compare_by_length ($string1, $string2);
>
> if ($longstring=="0"){
> echo "nochange" . $longstring;
> echo"<br>";
> }
> if ($longstring=="1"){
> echo "List " . $longstring;
> echo"<br>";
> $array1 = explode(",", $string1);
> $array2 = explode(",", $string2);
> }
> if ($longstring=="2"){
> echo "List " . $longstring;
> echo"<br>";
> $array1 = explode(",", $string2);
> $array2 = explode(",", $string1);
>
> }
>
> for ($i = 0; $i < count($array1); $i++) {
> $associative_array[$array1[$i]] = 1;
> }
>
> // print "Not a member of the following lists:<br>\n";
> for ($i = 0; $i < count($array2); $i++) {
> if (!$associative_array[$array2[$i]]) {
> print "$array2[$i]<br>\n";
> }
> }
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php