Well it took me a bit to find out how to do that but here it is:

I am doing a all check-in client for Foursquare and Gowalla and this is problematic:
first get all venues from Foursquare (obviously more populated than Gowalla) and list them, then get the name from the selected one and compare it with the Gowalla names in the array.
And the rest is history.

The hard part is comparing 2 strings but i found a function that can do that, well found 2:

similar_text("This is a text", "A text this is", $percent); // yoda stile :')
echo $percent; // 42.8571428571

This is quite good because it results are ok for 2-3 word names comparison.

Else there is the Levenshein argorithm

$lev = levenshtein("This is a text", "A text this is");
echo $lev; // 14

The result is quite disappointing for me but maybe someone else needs it.

PS: This class may be useful some day or for some one.

And yes, i am remaking the Foursquare Mobile Client aka 4sqr

By the way, anyone got a better idea for comparing 2 strings?

Back to coding now.

If this has been useful you should give me a beer

2 responses


Do you want to comment?

Comments RSS and TrackBack Identifier URI ?

$stringA = “hello world hello world helloo world”;
$stringB = “hello php hello php hello php”;

echo “string 1—->”.$stringA.”";
echo “string 2—->”.$stringB.”";

$array1 = explode(‘ ‘, $stringA);
$array2 = explode(‘ ‘, $stringB);

$result = array_diff($array2, $array1);

$zem= implode(‘ ‘,$result);
if (!empty($zem)) {

echo “string diffrence—> “.$zem.”";

}
else {
echo “string diffrence—>both strings are same “;
}

$a = count(explode(‘ ‘, $stringA));
$b= count(explode(” “, $zem));

similar_text($stringA, $stringB , $p);
echo ” similarity between the stirng is Percent:”.$p.”% “;

16 June 2011 07:21

<?
$str1 = "00009";
$str2 = "003";
$str3 = "00009-CODEMILES";

if ($str2 < $str1){
print("$str2 is less than $str1″);
}

if ($str3 < $str2){
print("$str3 is less than $str2″);
}
if ($str1 < $str3){
print("$str1 is less than $str3″);
}
?>

6 March 2012 07:42

Comment now!
















Trackbacks