Jump to content

Recommended Posts

HI.

 

 

Can anyone tell how i go about comparing three strings

to see if they are the same?

 

I'm building an Email list system, where users can upload

three of their friends Emails.

 

I want to check, to make sure they don't load up the same

Email three times.

 

I was thinking something like this, But  strcmp only compares

two strings. I need to compare three

strcmp (string $email1, string $email2, string $email3)

 

 

Any help would be great

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/52014-how-to-compare-three-strings/
Share on other sites

i'm not sure... but maybe if you make your own function (ex: compEmail($strin1,$string2,$string3))

 

<?php

function compEmail($email1,$email2,$email3)
{

if ($email1 == $email2 || $email1 == $email2) { return false; }
if ($email2 == $email1 || $email2 == $email3) { return false; }
if ($email3 == $email1 || $email3 == $email2) { return false; }
else { return true; }

}

?>

 

then you can use this:

<?php

$compEmail = compEmail($email1,$email2,$email3);
if ($compEmail) { 

// it's ok, continue the script

} else {

// one or more emails were the same

}

?>

 

be aware... it's not tested.. but it should get you started...

~clown

 

If a==b it follows that b==a, so you only need 3 tests for duplicates, not 6.

 

if ((a==b) || (b==c) || (a==c)) return false

 

And what if the user only wants to email a single friend, so b and c are both blank?

well... before comparing you must rule out any blank fields...

 

if (!empty($email1) && !empty($email2) && !empty($email3)) { compare them all }

 

etc

 

but about the ((a==b) || (b==c) || (a==c)) ... thanks for clearing that up for me... looks like i need to rewrite some codes myself :D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.