473,569 Members | 2,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help breaking up text for multiple pages

I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.
if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Fu ll_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Stor y = wordwrap($Game_ Full_Story,3800 ,"*#^");
$Game_Full_Stor y = explode ("*#^", $Game_Full_Stor y);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Stor y[$i];
if ($i != 0){
array_push($pag es, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story ,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}

Apr 27 '06 #1
4 1739
I'm a bit confused on the purpose of

$page = $page -1;

Aren't we moving from page 1 to page N? Shouldn't that be a $page++?
Anyways...

You mentioned you wanted breaks after each paragraph. I'm how that
that's what you else should look like in order to accomplish this.

}else{

$story = wordwrap($story ,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="<BR>"; //inserted break here
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .="<BR>";//inserted break here
}

Could you also provide a sample of what's in your database. So as i
could understand what's being worked with and what format the data is
in.

Apr 27 '06 #2
First, I have no idea why that code is there, as I didn't put it there
myself. *heh*

Actually, let me clear up what I was saying. Right now, something
somewhere in the coding of the site puts in <br/> tags for every
carrier return. (More on that in a moment.) So, my thought was, instead
of breaking up the text for separate pages at an arbitrary place, and
possibly cut a paragraph or sentence in half, I was thinking that if I
could have the PHP code break up the text at, say, every sixth grouping
of two <br/>s together, instead of say at X number of words or
characters. That way, each page would have like six paragraphs on it,
but that would also make it so that if I have an interview with a
question, one <br/>, and then the answer, it wouldn't break up the
question and answer.

Does that make sense?

As far as what is in the database, it's just plain old text. For
example, in the backend, I'll cut the review from my text editor, and
then paste it in. Either before or after it goes into the database, it
gets the <br/> tags added to it. (If it is important which step it is,
I can check.)

Apr 27 '06 #3
if there's already <br> in the database i don't think there should be a
need to do that in your code. What you could do is remove all breaks in
the database and let the code do that for you.

Apr 27 '06 #4
m.********@gmai l.com wrote:
I was recently put in charge of heading up my company's website, and
while I have a lot of experience on the design side of things, I'm
still very new to the programming side. When I started, the website had
just gotten a revision, but the site was an utter mess, so I've been
trying to fix it up. As I've gone along, I've learned some aspects of
PHP, but my knowledge is still very limited.

Here is the problem I'm trying to fix. A backend is used to enter
information into our MySQL database, and then a page template pulls it
out to make the page. For our reviews, the PHP coding currently breaks
up the review's text so that it can be places across multiple pages.
The problem is, the way the text breaking was set up, the end of one
page and the beginning of the next are totally chaotic, with breaks
often coming mid-sentence.

Here is what I'd love: other coding automatically puts an HTML break at
the end of paragraphs, and then another in the space between one
paragraph and the next. I'd love to have the code search for when those
double breaks come up, and then break up the text after, say, every
sixth pair of HTML breaks. I'd also like the option to break the text
myself by putting in some sort of text code in the original text. At
this point, though, anything that can make the breaks more elegant
would be a huge improvement.

I really appreciate any help anybody can give me in this one. Please
remember that I know very little of PHP, and I'm not much of a
programmer anyhow, so things that you may take for granted that people
would understand about PHP, I might not know.

I tried to pull out what I thought was the current coding for the text
break. Here it is. I'd also like to get rid of the part1/part2 factor.
Before, they had the text breaking to help in fitting into the layout
around an image, but I've fixed that so I no longer need the break. So,
that portion no longer needs to be a factor.
if ($page == ""){
$page = 1;
}
$no_letters = strlen($Game_Fu ll_Story);
$times = ($no_letters / 3800) +1;
$Game_Full_Stor y = wordwrap($Game_ Full_Story,3800 ,"*#^");
$Game_Full_Stor y = explode ("*#^", $Game_Full_Stor y);
$pages = array();
for ($i=0; $i<$times ; $i++){
$part[$i] = $Game_Full_Stor y[$i];
if ($i != 0){
array_push($pag es, $i);
}
}
$page = $page-1;
$story = $part[$page];
if (strlen($story) < 460){
$parts1 = $story;
}else{
$story = wordwrap($story ,460,"*#^");
$story = explode ("*#^", $story);
$parts1 = $story[0];
$count = count($story);
$parts2="";
for ($i=1; $i<$count; $i++){
$parts2 .=$story[$i];
$parts2 .=" ";
}
}


Well, could it be as simple as using strpos() to find the <br>s? (Actually in
this case stripos() would be better because it's not case sensitive) (Warning -
NOT tested!)

if (!isset($page) || $page == "")
$page = 1;

$pos = 0;
for ($cpage = 0; $cpage < $page; $cpage++) {
$pstart = $pos;
for ($cpar = 0; $cpar < 6; $cpar++) { // Change 6 to # of paras/page
$oldpos = $pos;
$pos = stripos($text, '<br>', $pos);
if ($pos === false) // no more found
break;
else
$pos++; // Point to next char and continue
}
}
if ($oldpos > $pstart)
echo substr($text, $pstart, $oldpos);
else
echo "End of article";

Probably not perfect, but it should get you started.

Alternatively, you could split the paragraphs into an array and just count the
number of items you need, i.e. (Again no tested)

if (!isset($page) || $page == "")
$page = 1;
$tarray = preg_split('/<br>/i', $text);
$pcount = 6; // Number of paragraphs per page
$startpar = ($page-1) * $pcount;
$endpar = min($startpar + $pcount, count($tarray)) ; // Don't go past end
for ($i = $startpar; $i < $endpar; $i+)
echo $tarray[$i];

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2391
by: leegold2 | last post by:
Hi, I have been looking around for a way to paginate php/mysql table output. There are a lot of hits when I google it. But unfortunately what I have tried either does not work or is imho just arcane code. So I am looking for a simple, clearly explained, and working pagination code snip that I can adapt, or a modular solution. I'd prefer...
15
1881
by: AMT2K5 | last post by:
Hello folks, I seem to have recieved a segfault within my function but am unsure on how to resolve it. I understand that it means that somewhere something is trying to access memory that is not prohibited or not available. The following function is an overloaded += operator that reads in strings in a record format seperated by comma...
87
6363
by: Frances Del Rio | last post by:
is there a non-breaking hyphen in HTML?? for example, so a phone no. falls all on one line.. as in.. 1-800-444-5454... (and is not broken into two lines if phone no. occurs near end of a line..) (searched for 'hyphen' in FAQ pg, didn't find anything..) thank you.. Frances
27
31381
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody somewhere said: Alternately, you can use CSS to declare a class having: ..nowrap { white-space:nowrap } .... and then wrap the compound word...
22
7986
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a way to denote a hyphen in HTML, that the line can be broken after? I've read some stuff about soft hyphens and non-breaking hyphens, but those...
2
14832
by: Patrick | last post by:
Hello - I am wondering what the command is for breaking quoted text over multiple lines for formatting in my code. An example is MessageBox.Show("You Fool! The number of registrants cannot be 0. Please re-enter the number of registrants.", _ "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Asterisk) I would like to break the text box...
16
2515
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and...
20
4240
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black...
9
2746
by: xprotocol | last post by:
Trying to print a web page that scrolls to right a bit. I would think IE would page break by default when it gets to the end of the sheet, but it doesn't, it just cuts off the print. This only needs to work in IE but FF does the same thing. I tried messing with some media="print" functionality on it but couldn't get any page breaks to...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.