Jump to content


Photo

Modifying a script help


  • Please log in to reply
5 replies to this topic

#1 zcrow

zcrow
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 June 2006 - 06:06 PM

I've got a script that paginates long articles into multiple pages. The article stored in the db has this code inserted where page breaks are supposed to happen: <p>[PAGE1]</p> content <p>[PAGE2]</p> etc.

This all works fine and I don't need any changes here but what I do need to do is create a print version of the article which would effectively display the entire text for the article and remove any instances of <p>[PAGE1]</p>, etc.

If anyone could help me with this I would really appreciate it.

The code for doing the page breaks looks like this:

//break article into pages if there are pages
$originaltext = $row_rs['content'];
$total=substr_count($originaltext,"[PAGE");
if ($_GET['pg'] && $_GET['pg']<$total+1)
{
$i=$_GET['pg'];
}
else { $i=1; }
// Next page
$k=$i+1;
$page="[PAGE".$i."]";
$nextpage="[PAGE".$k."]";
$start=strpos($originaltext,$page);
$start=$start+strlen($page)+1;
$end=strpos($originaltext,$nextpage);
$length=$end-($start+$pagesize);
$totalpages = $total;
if ($i==$total)
{
$text=substr($originaltext,$start);
}
else
{
$text=substr($originaltext,$start,$length);
}
//Removes end of </p> tag from page numbers
$text = substr($text,3);

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 21 June 2006 - 06:13 PM

What... and you want us to write it for you?

Take a look at the [a href=\"http://au.php.net/ereg_replace\" target=\"_blank\"]ereg_replace[/a] function.

#3 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 21 June 2006 - 06:16 PM

Alright you'll want to use eregi_replace or preg_replace to do this. I am not sure if you know anything about regular expressions but you can read a little here:

[a href=\"http://us2.php.net/eregi_replace\" target=\"_blank\"]http://us2.php.net/eregi_replace[/a]
[a href=\"http://weblogtoolscollection.com/regex/regex.php\" target=\"_blank\"]http://weblogtoolscollection.com/regex/regex.php[/a]

The code might look like this:
$clean_text = eregi_replace("<p>[PAGE.[0-9]]{1,2}.</p>", '', $old_text)

I have to be honest I am terrible at making regular expressions, so don't trust mine. Also I think the [ ] around the PAGE will make this hard, so you might consider replacing them with another symbol. At any rate to try to at least give you an idea of what I was attempting to do...
The [0-9] means any character between 0 and 9. the {1,2} means that there should be 1 or 2 numbers. The rest I think is clear. Hope this helps some.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#4 zcrow

zcrow
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 June 2006 - 06:19 PM

Thanks. I'm not expecting someone to write it for me but I wasn't sure how to do it. I thought there might be an easy-ish way to use the existing script and modifying it.

I will check out those function suggestions and see where that leads me.


#5 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 21 June 2006 - 06:26 PM

It really wouldn't have much at all to do with the current script. In fact id'e create it in a seperate file.

#6 zcrow

zcrow
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 21 June 2006 - 07:03 PM

[!--quoteo(post=386515:date=Jun 21 2006, 11:13 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 21 2006, 11:13 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What... and you want us to write it for you?

Take a look at the [a href=\"http://au.php.net/ereg_replace\" target=\"_blank\"]ereg_replace[/a] function.
[/quote]

This is my very first post to these forums. Not exactly a welcoming attitude. I came here hoping for help because I'm stuck. In the scale of things I guess I am a one or none green box kind of guy. Thank you for suggesting the ereg_replace function which I will look into but it doesn't really help us newcomers to start off with an attitude.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users