function GetLongestSubstring($str) {
$start = 0; $end = 0; $max = 0;
$size = strlen($str);
for ($i = 0; $i < $size - 1; $i++) {
for ($j = $i + 1; $j < $size; $j++) {
if ($str[$i] == $str[$j]) {
$temp = abs($j - $i - 1);
if ($temp > $max) {
$max = $temp;
$start = $i + 1;
$end = $j;
}
}
}
}
return substr($str,$start,$end - $start);
}
$str = "zXoDphpprogrammingDkmq";
$result = GetLongestSubstring($str);
echo $result;
/*
run:
phpprogramming
*/