PHP implements a method example for finding the longest common substring of two strings.
This example describes how to evaluate the longest public substring of two strings in PHP. We will share this with you for your reference. The details are as follows:
In the previous article, the PHP Method for Solving the longest public substrings is improved based on java. Here we will look at another public substrings algorithm.
The Code is as follows:
<? Php $ a = 'abceee12345309878 '; $ B = 'hangzhou'; $ c = array (); $ lenht1 = strlen ($ a); $ lenyy = strlen ($ B ); $ startTime = microtime (true); for ($ I = 0; $ I <$ lenht1; $ I ++) {for ($ j = 0; $ j <$ len22; $ j ++) {$ n = ($ I-1> = 0 & $ J-1> = 0 )? $ C [$ I-1] [$ J-1]: 0; $ n = ($ a [$ I] = $ B [$ j])? $ N + 1:0; $ c [$ I] [$ j] = $ n ;}} foreach ($ c as $ key => $ val) {$ max = max ($ val); foreach ($ val as $ key1 = >$ val1) {if ($ val1 = $ max & $ max> 0) {$ cdStr [$ max] = substr ($ B, $ key1-$ max + 1, $ max) ;}} ksort ($ cdStr ); $ endTime = microtime (true); echo "Totle time is ". ($ endTime-$ startTime ). "s ". "<br/>"; print_r (end ($ cdStr); exit;?>
Running result:
Totle time is 0.0012800693512 sabceee