PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
Copy Clear
Copy Format Clear
<?php $string1 = 'extension'; $string2 = 'tender'; $split = str_split($string2); $needle = ''; $matches = array(); foreach($split as $needleAppend) { if (!empty($needle)) { if (strpos($string1, $needle) === false) { $needle = ''; } else { $matches[] = $needle; } } $needle = empty($needle) ? $needleAppend : $needle . $needleAppend; } function sortByLength($a,$b) { return strlen($b)-strlen($a); } usort($matches, 'sortByLength'); $largestString = array_shift($matches); $remainder = substr($string2, strlen($largestString)); var_dump($matches);
Show:  
Copy Clear