PHP Function: Pagination


Here is my function for pagination:

function createPagination($pageLink,$page,$total_pages) {

	if($page > $total_pages || $total_pages == 1) { return ""; }

	echo "<div class="pagination">n";

	if($page != 1) {
		echo "<span class='nc'><a href="".$pageLink.($page - 1)."">< previous</a></span> &nbsp; &nbsp;n";
	}

	//FIND PREVIOUS FOUR
	$pageM1 = $page - 1;
	$pageM4 = $page - 4;
	if ($pageM4 > 1) { 

		echo "<span class='nc'><a href="".$pageLink."1">1</a></span> ... n";
	}

	for($i = $pageM4; $i < $page; $i++){
		if (($i < $total_pages) && ($i > 0)){
			echo "<a href="".$pageLink.$i ."">$i</a> n";
		}
	} 

	// DISPLAY CURRENT PAGE
	echo "<span class='co'><a href="".$pageLink.$i ."">$page</a></span> ";

	//FIND NEXT FOUR
	$pageP1 = $page + 1;
	$pageP4 = $pageP1 + 4;
	for($i = $pageP1; $i < $pageP4; $i++){
		if (($i <= $total_pages) && ($i != $page)) {
				echo "<a href="".$pageLink.$i ."">$i</a> n";
		}
	}
	if ($pageP4 <= $total_pages) {
		echo " ... <a href="" . $pageLink . $total_pages ."">$total_pages</a>n";
	}

	if($page != $total_pages) {
		echo "&nbsp; &nbsp; <span class='nc'><a href="".$pageLink.($page + 1)."">next ></a></span> n";
	}

	echo "</div>n";
}

And here is my CSS that I use to style it:

.pagination {
	text-align: center;
	margin: 25px 0px;
}
.pagination a {
	font: bold 11px arial;
	text-decoration: none !important;
	padding: 5px;
	color: #ffffff !important;
	border: solid 1px #909962;
	background: #AEB48E;
}
.pagination a:hover {
	background: #A2AB75;
	color: #ffffff !important;
}
.co {
	color: #ffffff !important;
	font: bold 18px arial;
	text-decoration: none !important;
	padding: 7px 4px;
	border: solid 1px #4D532E;
	background: #909962;
}