zcrow Posted June 21, 2006 Share Posted June 21, 2006 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); Quote Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/ Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 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 Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/#findComment-48152 Share on other sites More sharing options...
Buyocat Posted June 21, 2006 Share Posted June 21, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/#findComment-48153 Share on other sites More sharing options...
zcrow Posted June 21, 2006 Author Share Posted June 21, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/#findComment-48155 Share on other sites More sharing options...
trq Posted June 21, 2006 Share Posted June 21, 2006 It really wouldn't have much at all to do with the current script. In fact id'e create it in a seperate file. Quote Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/#findComment-48160 Share on other sites More sharing options...
zcrow Posted June 21, 2006 Author Share Posted June 21, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/12568-modifying-a-script-help/#findComment-48173 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.