HaLo2FrEeEk Posted August 12, 2007 Share Posted August 12, 2007 IS there a way to place pagination markers within a text block, and have the php read them and follow them, for example: [#newpage:1]Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla consequat. Pellentesque viverra turpis vel sapien. Sed consectetuer felis vel ante. Quisque egestas magna id justo. Nulla rutrum sodales ligula. Integer placerat purus sit amet libero. Pellentesque mauris. Aenean ut massa id mauris scelerisque tempor. Maecenas ipsum. Proin sodales. [#newpage:2]Donec pellentesque, enim sit amet nonummy volutpat, dui mauris condimentum odio, id mollis urna nulla id eros. Nulla commodo ligula sed eros. Morbi lectus mi, condimentum sit amet, volutpat volutpat, aliquam in, nulla. Vestibulum gravida. Curabitur erat nibh, dapibus vulputate, tincidunt sit amet, luctus nec, velit. Cras risus neque, lobortis at, faucibus in, varius non, nisi. Pellentesque leo risus, consectetuer ac, dictum quis, volutpat in, augue. Etiam ultricies. Etiam id purus. Nullam vel orci. Donec metus felis, rhoncus scelerisque, fermentum vitae, laoreet nec, erat. In pede elit, posuere vitae, mattis sed, viverra ut, leo. Nunc commodo ligula eget ipsum. Ut dignissim arcu nec dui. Nam in nunc nec eros porttitor venenatis. Vivamus id odio vitae felis iaculis feugiat. Ut venenatis tortor ac dui. [#newpage:3]Donec at justo sed arcu pharetra porttitor. Pellentesque accumsan consequat metus. Duis porttitor rhoncus massa. Proin lacinia ipsum ac nisl. Etiam condimentum malesuada est. Donec lacinia posuere ipsum. Duis eu augue vel nibh rutrum tincidunt. Nunc interdum lacus eu nibh. Aliquam neque. Sed elementum massa id elit. And then have a url like this: http://example.com/somepage.php?page=1 And it would only read from [#newpage:1] to [#newpage:2], printing out: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Nulla consequat. Pellentesque viverra turpis vel sapien. Sed consectetuer felis vel ante. Quisque egestas magna id justo. Nulla rutrum sodales ligula. Integer placerat purus sit amet libero. Pellentesque mauris. Aenean ut massa id mauris scelerisque tempor. Maecenas ipsum. Proin sodales. Is this possible and if so, how would I go about doing it? I have a tutorials section on my site and I don't feel like re-doing the database structure, if I could just modify the php page a little that would be a LOT easier. So...anyone? Quote Link to comment https://forums.phpfreaks.com/topic/64479-solved-in-text-pagination-help-please/ Share on other sites More sharing options...
sasa Posted August 12, 2007 Share Posted August 12, 2007 try <?php $a = file_get_contents('pages.txt'); $p = $_GET['page']; preg_match('/\[#newpage:'.$p.'\](.*)/',$a,$b); echo $text = isset($b[1]) ? $b[1] : 'no text to print'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64479-solved-in-text-pagination-help-please/#findComment-321468 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 12, 2007 Author Share Posted August 12, 2007 Sweet-NUSS. That helped. I've finished it up to figure out how many pages there are, then to write up a list with links to other pages, except the one you are on, that one is bolded, here: $snoopy->fetch("http://claninfectionist.com/misc/testing/pagetest.txt"); $text = $snoopy->results; $numpages = preg_match_all('/\[#newpage:(\d)\]/', $text, $pages); $numpages = max($pages[1]); $p = $_GET['page']; $p = (isset($p)) ? $p : 1 ; preg_match('/\[#newpage:'.$p.'\](.*)/', $text, $b); echo $text = isset($b[1]) ? $b[1] : 'no text to print'; echo "<br /><br />\n\n"; foreach($pages[1] as $page) { //echo ($page == $p) ? (($page == $numpages) ? $page : $page." | " ) : (($page == $numpages) ? $page : "<a href=\"{$_SERVER['PHP_SELF']}?page=".$page."\">".$page."</a> | " ) ; $pagenum = ($page == $p) ? "<b>".$page."</b>" : "<u><a href=\"{$_SERVER['PHP_SELF']}?page=".$page."\">".$page."</a></u>"; $pagenum .= ($page != $numpages) ? " | " : ''; echo $pagenum; } ?> Thank you for your help. Quote Link to comment https://forums.phpfreaks.com/topic/64479-solved-in-text-pagination-help-please/#findComment-321473 Share on other sites More sharing options...
sasa Posted August 12, 2007 Share Posted August 12, 2007 if you have more then 9 pages change line $numpages = preg_match_all('/\[#newpage:(\d)\]/', $text, $pages); to $numpages = preg_match_all('/\[#newpage:(\d+)\]/', $text, $pages); + mean one or more digits Quote Link to comment https://forums.phpfreaks.com/topic/64479-solved-in-text-pagination-help-please/#findComment-321516 Share on other sites More sharing options...
HaLo2FrEeEk Posted August 12, 2007 Author Share Posted August 12, 2007 Oh, thank you, I knew that but didn't think about it, thank you for the pointer and thank you a bunch for the regex, it REALLY helped, now I can organize my tutorials a little better. Quote Link to comment https://forums.phpfreaks.com/topic/64479-solved-in-text-pagination-help-please/#findComment-321560 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.