General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 15th, 2003, 05:37 PM
tylendel98 tylendel98 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 5 tylendel98 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 59 m 52 sec
Reputation Power: 0
Please help with REGEX

Hello,

Could someone please assist me with a little regex issue?

The following code produces paging links in the form - page 1 etc
by putting [page] where I want it to break the text.

What I would like it to do is produce a list of page title links by doing this [page=something].

Thanks in advance

PHP Code:
<?php

function page_break($text) {

if (
ereg("\[page]",$text))
{
     
$pages split("\[page]",$text);
     if (!
$pages[0]) array_shift($pages);
     
$x count($pages);
     if(!
$pagebreak$pagebreak 1;

     
$text $pages[$pagebreak-1];

     
$page_nav "<p>";
     if (
$pagebreak != 1)
     {
         
$prevpage $pagebreak 1;
         
$page_nav .= "<a href=\"$PHP_SELF?pagebreak=$prevpage\"
title=\"Page $prevpage\"><< | </a> "
;

     }
     for(
$i 1$i <= count($pages); $i++)
     {
         
$page_nav .= "<a href=\"$PHP_SELF?pagebreak=$i\" title=\"Page
$i\">Page $i</a> | "
;
     }
     if (
$pagebreak $x)
     {
         
$nextpage $pagebreak 1;
         
$page_nav .= "<a href=\"$PHP_SELF?pagebreak=$nextpage\"
title=\"Page $nextpage\">>></a> "
;
     }
     
$page_nav .= "</p>";
     
$text .= $page_nav;
}

?>

Reply With Quote
  #2  
Old July 16th, 2003, 05:36 PM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
If you're trying to match the literal string '[page]', you have to escape the brackets in your regex... ereg('\[page\]', $text)

Reply With Quote
  #3  
Old July 16th, 2003, 09:16 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 7
As the crazy one said - but also if you just need to match the [page] within the blob - don't even use the slow regex, use something like this:
PHP Code:
if ( stristr$page_data'[page]' ) )
{
        
/* true - [page] found in blob */
}
else
{
        
/* false - [page] not found in blob */


Now, you mentioned [page=something] in your post, but i don't see that in your code. If this is the case, you need to use something like this:
Code:
if ( preg_match( '/\[page=(.*?)\]/', $page_data, $match ) )
{
        /* Found - the page name is held in $match[1] */
}

This brings us to the next question - will there be mulitple pages on this - if so, you need preg_split() and a preg_match_all() combination and a little helping hand on getting the array() data out of the $match array in order of page sequence...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Please help with REGEX


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT