Jump to content

Recommended Posts

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);
Link to comment
https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/
Share on other sites

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.
[!--quoteo(post=386515:date=Jun 21 2006, 11:13 AM:name=thorpe)--][div class=\'quotetop\']QUOTE(thorpe @ Jun 21 2006, 11:13 AM) [snapback]386515[/snapback][/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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.