Basically i want to limit the amount of numbers displayed on my page, but currently it's displaying 31 numbers, because their is 31 pages of results, i'd like to show 5 links and just increment after every page,
Here's how they're currently being displayed
[1] [2] [3] [4] [5] [6] [7] [8] etc..
Here's what i'd like
[1] [2] [3] [4] [5]
What i'd like i just but once you select for example number 8, it'd place that number in the middle and 2 links either side for example like this
[6] [7] [8] [9] [10]
Here's the current code that i'm using
function showPageNumbers($totalrows,$page,$limit){
$query_string = $this->queryString();
$pagination_links = null;
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
$pagination_links .= '<li class="active">'.$i.'</li>';
}else{
$pagination_links .= '<li>'.$i.'</li>';
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
$pagination_links .= '<li class="active">'.$i.'</li>';
}else{
$pagination_links .= '<li>'.$i.'</li>';
}
}
return $pagination_links;
}
You can have modified function like:
function showPageNumbers($totalrows, $page, $limit){
$query_string = $this->queryString();
$pagination_links = null;
$numofpages = $totalrows / $limit;
$linksPerPage = 5;
$firstNum = $page - round(($linksPerPage)/2);
if($firstNum < 1)
$firstNum =1;
$lastNum = $firstNum + $linksPerPage -1;
if($lastNum > $numofpages)
$lastNum = $numofpages;
for($i = $firstNum; $i <= $lastNum; $i++){
if($i == $page){
$pagination_links .= '<li class="active">'.$i.'</li>';
}else{
$pagination_links .= '<li>'.$i.'</li>';
}
}
return $pagination_links;
}
Related
I have a pagination script with PHP. When page records are some hundreds, the pagination result is too big. How I can limit the page numbers/links?
Example: < 1 | 2 ... 37 | 38 | 39 | 40 | 41 | 42 ... 82 | 83 >
This is my PHP script
<?php
$ppp = 10;
$rows = mysql_num_rows($query);
$nmpages = ceil($rows/$ppp);
// if current page is not 1, draw PREVIOUS link
if ($pg > 1 && $nmpages != 0) {
echo "< ";
}
For($i = 1 ; $i <= $nmpages ; $i++) {
If($i == $pg) {
echo "<b>".$i."</b> ";
} else {
echo "".$i." ";
}
}
// if current page less than max pages, draw NEXT link
if ($pg < $nmpages && $nmpages != 0) {
echo ">";
}
?>
Do you have an ideas how I can do this with the specific PHP script that I have?
Try this :
<?php
$link = "";
$page = $_GET['pg']; // your current page
// $pages=20; // Total number of pages
$limit=5 ; // May be what you are looking for
if ($pages >=1 && $page <= $pages)
{
$counter = 1;
$link = "";
if ($page > ($limit/2))
{ $link .= "1 ... ";}
for ($x=$page; $x<=$pages;$x++)
{
if($counter < $limit)
$link .= "".$x." ";
$counter++;
}
if ($page < $pages - ($limit/2))
{ $link .= "... " . "".$pages." "; }
}
echo $link;
?>
OUTPUT :
//At page=1
1 2 3 4 ... 20
//At page=12
1 ... 12 13 14 15 ... 20
//At page=18
1 ... 18 19 20
An improvement or rather re-write based on #Makesh's code.
function get_pagination_links($current_page, $total_pages, $url)
{
$links = "";
if ($total_pages >= 1 && $current_page <= $total_pages) {
$links .= "1";
$i = max(2, $current_page - 5);
if ($i > 2)
$links .= " ... ";
for (; $i < min($current_page + 6, $total_pages); $i++) {
$links .= "{$i}";
}
if ($i != $total_pages)
$links .= " ... ";
$links .= "{$total_pages}";
}
return $links;
}
OUTPUT:
page = 1
1 2 3 4 5 6 ... 20
page = 10
1 ... 5 6 7 8 9 10 11 12 13 14 15 ... 20
page = 19
1 ... 14 15 16 17 18 19 20
The answer for this question was basically to visit a page about Digg style pagination which includes code samples.
So that's the answer, but this question is basically a duplicate.
Try to make a page bracket for example 10 less and 10 more than the actual page, change for example the for statement for this:
For($i = $pg-10 ; $i <= $pg+10 ; $i++)
I wanted to get an array of numbers by the current page and total page. So this is what I came up with. I hope this helps others -
Caution - this work if total page is more than 10. I felt if the total
page is less than 10 then just show it in a single for loop.
function getSmartPageNumbers($currentPage, $totalPage)
{
$pageNumbers = [];
$diff = 2;
$firstChunk = [1, 2, 3];
$lastChunk = [$totalPage - 2, $totalPage - 1, $totalPage];
if ($currentPage < $totalPage) {
$loopStartAt = $currentPage - $diff;
if ($loopStartAt < 1) {
$loopStartAt = 1;
}
$loopEndAt = $loopStartAt + ($diff * 2);
if ($loopEndAt > $totalPage) {
$loopEndAt = $totalPage;
$loopStartAt = $loopEndAt - ($diff * 2);
}
if (!in_array($loopStartAt, $firstChunk)) {
foreach ($firstChunk as $i) {
$pageNumbers[] = $i;
}
$pageNumbers[] = '.';
}
for ($i = $loopStartAt; $i <= $loopEndAt; $i++) {
$pageNumbers[] = $i;
}
if (!in_array($loopEndAt, $lastChunk)) {
$pageNumbers[] = '.';
foreach ($lastChunk as $i) {
$pageNumbers[] = $i;
}
}
}
return $pageNumbers;
}
Test:
getSmartPageNumbers(8, 20);
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => .
[4] => 6
[5] => 7
[6] => 8
[7] => 9
[8] => 10
[9] => .
[10] => 18
[11] => 19
[12] => 20
)
getSmartPageNumbers(1, 20);
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
[5] => .
[6] => 18
[7] => 19
[8] => 20
)
Right now my pagination would show up something like this
[1] [2] [3] [4] [5] [6] [7] [8] [9]
How would i make it show up like this
[1] [2] [3] [4] [5]... [9]
<?php
$per_page = 10;
$pages_query = mysql_query ("SELECT COUNT(`message_id`) FROM `messages`") or die(mysql_error());
$pages = ceil(mysql_result ($pages_query, 0) / $per_page);
$page = (isset ($_GET['page'])) ? (int) $_GET['page'] : 1;
$start = ($page - 1) * $per_page;
?>
Relevant if statement that echo out pagination
<?php
if ($pages >=1 && $page <= $pages) {
for ($x=1; $x<=$pages;$x++) {
echo "".$x."";
}
}
?>
Try this :
<?php
$link = "";
// $page = $_GET['page'];
// $pages=20; // Hardcoded for testing purpose
$limit=5 ;
if ($pages >=1 && $page <= $pages)
{
$counter = 1;
$link = "";
if ($page > ($limit/2))
{ $link .= "1 ... ";}
for ($x=$page; $x<=$pages;$x++)
{
if($counter < $limit)
$link .= "".$x." ";
$counter++;
}
if ($page < $pages - ($limit/2))
{ $link .= "... " . "".$pages." "; }
}
echo $link;
?>
OUTPUT :
//At page=1
1 2 3 4 ... 20
//At page=12
1 ... 12 13 14 15 ... 20
//At page=18
1 ... 18 19 20
<?php
if ($pages >=1 && $page <= $pages) {
$counter = 1;
$link = "";
for ($x=1; $x<=$pages;$x++) {
if($counter < 5)
$link .= "".$x."";
$counter++;
}
$link .= "...";
$link .= "".$pages."";
}
echo $link;
?>
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 4 years ago.
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>" : "{$i}";
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>" : "{$i}";
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>" : "{$i}";
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>" : "{$i}";
if ( $i < $total_pages )
{
$page_string .= ", ";
break;
}
}
} while (0);
if ( 1 < $on_page )
{
$page_string = " <font size='2'>"."«"."</font> ".$page_string;
}
if ( $on_page < $total_pages )
{
$page_string .= " <font size='2'>"."»"."</font>";
}
$page_string = "Pages ({$total_pages}):"." ".$page_string;
return $page_string;
}
}
The code around while (0); followed by if (1 < $on_page) looks wrong to me. At a glance it looks like the else is not closed. Have you tried php -l (lint) on your code?
Put a } in the last line of your code. You are just not closing the body of your function.
Of course it could also be that you are missing a closing bracket somewhere in between.
But as we don't know how the code works (i.e. we don't know when which block should be executed), you should intend it correctly from the beginning and look over it again.
You need a } at the end of the file to close the function body.
You are missing a closing } for the do statement starting on line 65.
Replace that statement with the following text to repair it.
do
{
$i = 1;
for ( ; $i < $total_pages + 1; ++$i)
{
$page_string .= $i == $on_page ? "<font face='verdana' size='2'><b>[{$i}]</b></font>" : "{$i}";
if ( $i < $total_pages )
{
$page_string .= ", ";
break;
}
}
} while (0);
your indentation inside the do ... while(0) code is off. If you look at the for loop, you'll notice that everything inside it is one indentation less than it should be.
Add this indentation, and you'll see that what the others mentioned (extra } at the end of the file) is the problem.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm looking for an example algorithm of smart pagination. By smart, what I mean is that I only want to show, for example, 2 adjacent pages to the current page, so instead of ending up with a ridiculously long page list, I truncate it.
Here's a quick example to make it clearer... this is what I have now:
Pages: 1 2 3 4 [5] 6 7 8 9 10 11
This is what I want to end up with:
Pages: ... 3 4 [5] 6 7 ...
(In this example, I'm only showing 2 adjacent pages to the current page)
I'm implementing it in PHP/Mysql, and the "basic" pagination (no trucating) is already coded, I'm just looking for an example to optimize it... It can be an example in any language, as long as it gives me an idea as to how to implement it...
Here is some code based on original code from this very old link. It uses markup compatible with Bootstrap's pagination component, and outputs page links like this:
[1] 2 3 4 5 6 ... 100
1 [2] 3 4 5 6 ... 100
...
1 2 ... 14 15 [16] 17 18 ... 100
...
1 2 ... 97 [98] 99 100
<?php
// How many adjacent pages should be shown on each side?
$adjacents = 3;
//how many items to show per page
$limit = 5;
// if no page var is given, default to 1.
$page = (int)$_GET["page"] ?? 1;
//first item to display on this page
$start = ($page - 1) * $limit;
/* Get data. */
$data = $db
->query("SELECT * FROM mytable LIMIT $start, $limit")
->fetchAll();
$total_pages = count($data);
/* Setup page vars for display. */
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages / $limit);
//last page minus 1
$lpm1 = $lastpage - 1;
$first_pages = "<li class='page-item'><a class='page-link' href='?page=1'>1</a></li>" .
"<li class='page-item'><a class='page-link' href='?page=2'>2</a>";
$ellipsis = "<li class='page-item disabled'><span class='page-link'>...</span></li>";
$last_pages = "<li class='page-item'><a class='page-link' href='?page=$lpm1'>$lpm1</a></li>" .
"<li class='page-item'><a class='page-link' href='?page=$lastpage'>$lastpage</a>";
$pagination = "<nav aria-label='page navigation'>";
$pagincation .= "<ul class='pagination'>";
//previous button
$disabled = ($page === 1) ? "disabled" : "";
$pagination.= "<li class='page-item $disabled'><a class='page-link' href='?page=$prev'>« previous</a></li>";
//pages
//not enough pages to bother breaking it up
if ($lastpage < 7 + ($adjacents * 2)) {
for ($i = 1; $i <= $lastpage; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
} elseif($lastpage > 5 + ($adjacents * 2)) {
//enough pages to hide some
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2)) {
for ($i = 1; $i < 4 + ($adjacents * 2); $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
$pagination .= $ellipsis;
$pagination .= $last_pages;
} elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
//in middle; hide some front and some back
$pagination .= $first_pages;
$pagination .= $ellipsis
for ($i = $page - $adjacents; $i <= $page + $adjacents; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
$pagination .= $ellipsis;
$pagination .= $last_pages;
} else {
//close to end; only hide early pages
$pagination .= $first_pages;
$pagination .= $ellipsis;
$pagination .= "<li class='page-item disabled'><span class='page-link'>...</span></li>";
for ($i = $lastpage - (2 + ($adjacents * 2)); $i <= $lastpage; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
}
}
//next button
$disabled = ($page === $last) ? "disabled" : "";
$pagination.= "<li class='page-item $disabled'><a class='page-link' href='?page=$next'>next »</a></li>";
$pagination .= "</ul></nav>";
if($lastpage <= 1) {
$pagination = "";
}
echo $pagination;
foreach ($data as $row) {
// display your data
}
echo $pagination;
Kinda late =), but here is my go at it:
function Pagination($data, $limit = null, $current = null, $adjacents = null)
{
$result = array();
if (isset($data, $limit) === true)
{
$result = range(1, ceil($data / $limit));
if (isset($current, $adjacents) === true)
{
if (($adjacents = floor($adjacents / 2) * 2 + 1) >= 1)
{
$result = array_slice($result, max(0, min(count($result) - $adjacents, intval($current) - ceil($adjacents / 2))), $adjacents);
}
}
}
return $result;
}
Example:
$total = 1024;
$per_page = 10;
$current_page = 2;
$adjacent_links = 4;
print_r(Pagination($total, $per_page, $current_page, $adjacent_links));
Output (# Codepad):
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
Another example:
$total = 1024;
$per_page = 10;
$current_page = 42;
$adjacent_links = 4;
print_r(Pagination($total, $per_page, $current_page, $adjacent_links));
Output (# Codepad):
Array
(
[0] => 40
[1] => 41
[2] => 42
[3] => 43
[4] => 44
)
I started from the lazaro's post and tried to make a robust and light algorithm with javascript/jquery...
No additional and/or bulky pagination libraries needed...
Look on fiddle for an live example: http://jsfiddle.net/97JtZ/1/
var totalPages = 50, buttons = 5;
var currentPage = lowerLimit = upperLimit = Math.min(9, totalPages);
//Search boundaries
for (var b = 1; b < buttons && b < totalPages;) {
if (lowerLimit > 1 ) { lowerLimit--; b++; }
if (b < buttons && upperLimit < totalPages) { upperLimit++; b++; }
}
//Do output to a html element
for (var i = lowerLimit; i <= upperLimit; i++) {
if (i == currentPage) $('#pager').append('<li>' + i + '</li> ');
else $('#pager').append('<li><em>' + i + '</em></li> ');
}
List<int> pages = new List<int>();
int pn = 2; //example of actual pagenumber
int total = 8;
for(int i = pn - 9; i <= pn + 9; i++)
{
if(i < 1) continue;
if(i > total) break;
pages.Add(i);
}
return pages;
I made a pagination class and put in on Google Code a while ago. Check it out its pretty simple
http://code.google.com/p/spaceshipcollaborative/wiki/PHPagination
$paging = new Pagination();
$paging->set('urlscheme','class.pagination.php?page=%page%');
$paging->set('perpage',10);
$paging->set('page',15);
$paging->set('total',3000);
$paging->set('nexttext','Next Page');
$paging->set('prevtext','Previous Page');
$paging->set('focusedclass','selected');
$paging->set('delimiter','');
$paging->set('numlinks',9);
$paging->display();
I would use something simple on the page you are showing the paginator, like:
if (
$page_number == 1 || $page_number == $last_page ||
$page_number == $actual_page ||
$page_number == $actual_page+1 || $page_number == $actual_page+2 ||
$page_number == $actual_page-1 || $page_number == $actual_page-2
) echo $page_number;
You can adapt it to show each 10 or so pages with % operator ...
I think using switch() case would be better in this case, I just don't remember the syntax now
Keep it Simple :)
If it's possible to generate the pagination on the client, I would suggest my new Pagination plugin: http://www.xarg.org/2011/09/jquery-pagination-revised/
The solution to your question would be:
$("#pagination").paging(1000, { // Your number of elements
format: '. - nncnn - ', // Format to get Pages: ... 3 4 [5] 6 7 ...
onSelect: function (page) {
// add code which gets executed when user selects a page
},
onFormat: function (type) {
switch (type) {
case 'block': // n and c
return '<a>' + this.value + '</a>';
case 'fill': // -
return '...';
case 'leap': // .
return 'Pages:';
}
}
});
The code of the CodeIgniter pagination-class can be found on GitHub
(what you call) Smart pagination can be achieved by configuration.
$config['num_links'] = 2;
The number of "digit" links you would like before and after the
selected page number. For example, the number 2 will place two digits
on either side, as in the example links at the very top of this page.
So I'm doing this in PHP but it is a logic issue so I'll try to write it as generically as possible.
To start here's how this pagination script works:
for (draw first three pages links)
if (draw ellipsis (...) if there are pages between #1's pages and #3's pages)
for (draw current page and two pages on each side of it links)
if (draw elipsis (...) if there are pages between #3's pages and #5's pages)
for (draw final three pages links)
The problem is that when there are low amounts of pages (I noticed this when the page count was at 10) there should be an ellipsis but none is drawn.
Onto the code:
$page_count = 10; //in actual code this is set properly
$current_page = 1; //in actual code this is set properly
for ($i = 1;$i <= 3;$i++)
{
if ($page_count >= $i)
echo $i;
}
if ($page_count > 3 && $current_page >= 7)
echo "...";
for ($i = $current_page - 2;$i <= current_page + 2;$i++)
{
if ($i > 3 && $i < $page_count - 2)
echo $i;
}
if ($page_count > 13 && $current_page < $page_count - 5)
echo "...";
for ($i = $page_count - 2;$i <= $page_count;$i++)
{
if ($page_count > 3)
echo $i;
}
So I figure the best idea would to be to modify one of the two ellipsis if statements to include a case like this, however I've tried and am stumped.
Also please note that I condensed this code for readability sake so please don't give tips like "those for loops are ineffective because they will recalculate current_page - 2 for each iteration" because I know :)
For those whom want to see a breakdown of how this logic currently works, here is example output ( modified ) with iterating $page_count and $current_page.
http://rafb.net/p/TNa56h71.html
<?php
/**
* windowsize must be odd
*
* #param int $totalItems
* #param int $currentPage
* #param int $windowSize
* #param int $anchorSize
* #param int $itemsPerPage
* #return void
*/
function paginate($totalItems, $currentPage=1, $windowSize=3, $anchorSize=3, $itemsPerPage=10) {
$halfWindowSize = ($windowSize-1)/2;
$totalPages = ceil($totalItems / $itemsPerPage);
$elipsesCount = 0;
for ($page = 1; $page <= $totalPages; $page++) {
// do we display a link for this page or not?
if ( $page <= $anchorSize ||
$page > $totalPages - $anchorSize ||
($page >= $currentPage - $halfWindowSize &&
$page <= $currentPage + $halfWindowSize) ||
($page == $anchorSize + 1 &&
$page == $currentPage - $halfWindowSize - 1) ||
($page == $totalPages - $anchorSize &&
$page == $currentPage + $halfWindowSize + 1 ))
{
$elipsesCount = 0;
if ($page == $currentPage)
echo ">$page< ";
else
echo "[$page] ";
// if not, have we already shown the elipses?
} elseif ($elipsesCount == 0) {
echo "... ";
$elipsesCount+=1; // make sure we only show it once
}
}
echo "\n";
}
//
// Examples and output
//
paginate(1000, 1, 3, 3);
// >1< [2] [3] ... [98] [99] [100]
paginate(1000, 7, 3, 3);
// [1] [2] [3] ... [6] >7< [8] ... [98] [99] [100]
paginate(1000, 4, 3, 3);
// [1] [2] [3] >4< [5] ... [98] [99] [100]
paginate(1000, 32, 3, 3);
// [1] [2] [3] ... [31] >32< [33] ... [98] [99] [100]
paginate(1000, 42, 7, 2);
// [1] [2] ... [39] [40] [41] >42< [43] [44] [45] ... [99] [100]
This is probably an overcomplicated solution, but it works.
I've used an array here instead of just printing, which lets me "do-over" the logic.
Part of the problem occurs when "left and right of page" happens to coincide with left-and-right shoulders.
function cdotinator ( $current_page, $page_count )
{
$stepsize = 3;
$elipse = '...';
# Simple Case.
if ( $page_count <= 2 * $stepsize )
{
$out = range( 1, $page_count );
$out[$current_page - 1 ] = '*' . $current_page . '*';
return $out;
}
#Complex Case
# 1) Create All Pages
$out = range( 1, $page_count );
# 2 ) Replace "middle" pages with "." placeholder elements
for( $i = $stepsize+1 ; $i <= ( $page_count - $stepsize ) ; $i ++ )
{
$out[ $i - 1 ] = '.' ;
}
# 3.1 ) Insert the pages around the current page
for( $i = max(1,( $current_page - floor($stepsize / 2) )) ;
$i <= min( $page_count,( $current_page + floor( $stepsize/2)));
$i ++ )
{
$out[ $i - 1] = $i;
}
# 3.2 Bold Current Item
$out[ $current_page - 1 ] = '*' . $current_page . '*' ;
# 4 ) Grep out repeated '.' sequences and replace them with elipses
$out2 = array();
foreach( $out as $i => $v )
{
# end, current == peek()
end($out2);
if( current($out2) == $elipse and $v == '.' )
{
continue;
}
if( $v == '.' )
{
$out2[] = $elipse;
continue;
}
$out2[]= $v;
}
return $out2;
}
Output can be seen here: http://dpaste.com/92648/