Skip to content

Instantly share code, notes, and snippets.

@iamtchelo
Forked from netojoaobatista/gist:6703131
Last active August 29, 2015 14:08
Show Gist options
  • Save iamtchelo/1944d411b52cbfa2abb9 to your computer and use it in GitHub Desktop.
Save iamtchelo/1944d411b52cbfa2abb9 to your computer and use it in GitHub Desktop.
Regular Expression
<?php
$string = '04/09/2013 VANESSA RAFFLER 5199060 28/08/2013 13:40 EMISSAO CO IBITINGA 01 28/08/2013 18:58 TRANSFERENCIA TECA JAD SAO 29/08/2013 00:23 ENTRADA TECA JAD SAO 29/08/2013 02:50 TRANSFERENCIA CO CURITIBA 01 29/08/2013 10:23 TRANSFERENCIA CO UNIAO DA VITORIA 01 29/08/2013 20:20 TRANSFERENCIA CO CURITIBA 01 29/08/2013 23:52 TRANSFERENCIA CO CURITIBA 01 30/08/2013 06:50 TRANSFERENCIA CO UNIAO DA VITORIA 01 30/08/2013 12:44 TRANSFERENCIA CO CHAPECO 01 02/09/2013 08:01 ENTRADA CO CHAPECO 01 02/09/2013 09:50 EM ROTA CO CHAPECO 01 03/09/2013 09:22 ENTREGUE CO CHAPECO 01 03/09/2013 09:26 ENDERECO NAO LOCALIZADO CO CHAPECO 01 04/09/2013 09:40 EM ROTA CO CHAPECO 01 05/09/2013 09:06 ENTREGUE CO CHAPECO 01';
if (preg_match_all('/[^\s].*?(?=\d{2}\/\d{2}\/\d{4})/', $string, $matches)) {
$limit = 3;
$page = (isset($_GET['page'])) ? $_GET['page'] : (int) 1;
$split_data = array_chunk($matches[0], $limit);
$total_page = count($split_data);
$result = $split_data[$page-1];
foreach ($result as $data) {
printf('<p>%s</p>', $data);
}
// pagination
for ($i = 1; $i < $total_page+1; $i++) {
// current page
if ($page == $i) {
printf('<strong>%d</strong>', $i);
} else {
printf('<a href="%s">%d</a>', '?' . http_build_query(array(
'page' => $i
)), $i);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment