How can I find the Largest Common Substring between two strings in PHP?

Is there a fast algorithm for finding the Largest Common Substring in two strings or is it an NPComplete problem?

In PHP, I can find a needle in a haystack:


if (strstr("there is a needle in a haystack", "needle")) {
    echo "found<br>\n";

I guess I could do this in a loop over one of the strings but that would be very expensive! Especially since my application of this is to search a database of email and look for spam (i.e. similar emails sent by the same person).

Does anyone have any PHP code they can throw out there?


The similar_text function may be what you want.

This calculates the similarity between two strings. Returns the number of matching chars in both strings

You may also want to look at levenshtein

Need Your Help

check status (enable / disable) of a draggable element in jquery

jquery jquery-ui draggable jquery-ui-draggable

I have some elements which are draggables and I'm changing their status (enable / disable) like this:

Uniquely identify a user on WinRT and WP8 using (f.ex.) LiveID?

windows-runtime unique identify liveid

I am looking for a way to uniquely identify a user in WinRT and preferably in WP8 as well. In WP7 applications, I could get a hash of the Live ID to do this, but I am not sure of how to approach th...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.