Demo entry 2367757

sad

   

Submitted by adicom on Aug 15, 2015 at 21:30
Language: PHP. Code size: 615 Bytes.

function longest_palind($s) {
    $str = "";
    $t = true;
    $temp = '';
    for($i=0; $i<strlen($s)-1; $i++) {
        for($j=strlen($s)-1; $j>=$i+1; $j--) {
            if($s[$i] == $s[$j]) {
                $t = true;
                for($k=$i,$l=$j; $k<=$l; $k++,$l--) {
                    if($s[$k] != $s[$l]) {
                        $t = false;
                        break;
                    }
                }
                if($t==true) $temp = substr($s, $i, $j-$i+1);
            }
            if(strlen($temp)>=strlen($str)) $str=$temp; 
        }
    }
    echo $str;
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).