Code review - PHP syntax error unexpected $end

Posted by dtufano on Stack Overflow See other posts from Stack Overflow or by dtufano
Published on 2010-03-30T07:29:25Z Indexed on 2010/03/30 7:33 UTC
Read the original article Hit count: 459

Filed under:
|
|
|

Hey guys! I keep getting a syntax error (unexpected $end), and I've isolated it to this chunk of code. I can't for the life of me see any closure issues. It's probably something obvious but I'm going nutty trying to find it. Would appreciate an additional set of eyes.

function generate_pagination( $base_url, $num_items, $per_page, $start_item, $add_prevnext_text = TRUE )
    {
        global $lang;
        if ( $num_items == 0 )
        {
        }
        else
        {
            $total_pages = ceil( $num_items / $per_page );
            if ( $total_pages == 1 )
            {
                return "";
            }
            $on_page = floor( $start_item / $per_page ) + 1;
            $page_string = "";
            if ( 8 < $total_pages )
            {
                $init_page_max = 2 < $total_pages ? 2 : $total_pages;
                $i = 1;
                for ( ; $i < $init_page_max + 1; ++$i )
                {
                    $page_string .= $i == $on_page ? "<font face='verdana' size='2'><b>[{$i}]</b></font>" : "<a href=\"".$base_url."&amp;offset=".( $i - 1 ) * $per_page."\">{$i}</a>";
                    if ( $i < $init_page_max )
                    {
                        $page_string .= ", ";
                    }
                }
                if ( 2 < $total_pages )
                {
                    if ( 1 < $on_page && $on_page < $total_pages )
                    {
                        $page_string .= 4 < $on_page ? " ... " : ", ";
                        $init_page_min = 3 < $on_page ? $on_page : 4;
                        $init_page_max = $on_page < $total_pages - 3 ? $on_page : $total_pages - 3;
                        $i = $init_page_min - 1;
                        for ( ; $i < $init_page_max + 2; ++$i )
                        {
                            $page_string .= $i == $on_page ? "<font face='verdana' size='2'><b>[{$i}]</b></font>" : "<a href=\"".$base_url."&amp;offset=".( $i - 1 ) * $per_page."\">{$i}</a>";
                            if ( $i < $init_page_max + 1 )
                            {
                                $page_string .= ", ";
                            }
                        }
                        $page_string .= $on_page < $total_pages - 3 ? " ... " : ", ";
                    }
                    else
                    {
                        $page_string .= " ... ";
                    }
                    $i = $total_pages - 1;
                    for ( ; $i < $total_pages + 1; ++$i )
                    {
                        $page_string .= $i == $on_page ? "<font face='verdana' size='2'><b>[{$i}]</b></font>" : "<a href=\"".$base_url."&amp;offset=".( $i - 1 ) * $per_page."\">{$i}</a>";
                        if ( $i < $total_pages )
                        {
                            $page_string .= ", ";
                        }
                    }
                    continue;
                }
            }
            else
            {
                do
                {
                    $i = 1;
                    for ( ; $i < $total_pages + 1; ++$i)

                {
                    $page_string .= $i == $on_page ? "<font face='verdana' size='2'><b>[{$i}]</b></font>" : "<a href=\"".$base_url."&amp;offset=".( $i - 1 ) * $per_page."\">{$i}</a>";
                    if ( $i < $total_pages )
                    {
                        $page_string .= ", ";
                        break;
                    }
                } 
            } while (0);
            if ( 1 < $on_page )
            {
                $page_string = " <font size='2'><a href=\"".$base_url."&amp;offset=".( $on_page - 2 ) * $per_page."\">"."&laquo;"."</a></font>&nbsp;&nbsp;".$page_string;
            }
            if ( $on_page < $total_pages )
            {
                $page_string .= "&nbsp;&nbsp;<font size='2'><a href=\"".$base_url."&amp;offset=".$on_page * $per_page."\">"."&raquo;"."</a></font>";
            }
            $page_string = "Pages ({$total_pages}):"." ".$page_string;
            return $page_string;
        }
    }

© Stack Overflow or respective owner

Related posts about php

Related posts about error